Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
86
Task/Queue-Usage/Action-/queue-usage.action
Normal file
86
Task/Queue-Usage/Action-/queue-usage.action
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
CARD EndProg ;required for ALLOCATE.ACT
|
||||
|
||||
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program!
|
||||
|
||||
DEFINE PTR="CARD"
|
||||
DEFINE NODE_SIZE="4"
|
||||
TYPE QueueNode=[PTR data,nxt]
|
||||
|
||||
QueueNode POINTER queueFront,queueRear
|
||||
|
||||
BYTE FUNC IsEmpty()
|
||||
IF queueFront=0 THEN
|
||||
RETURN (1)
|
||||
FI
|
||||
RETURN (0)
|
||||
|
||||
PROC Push(CHAR ARRAY v)
|
||||
QueueNode POINTER node
|
||||
|
||||
node=Alloc(NODE_SIZE)
|
||||
node.data=v
|
||||
node.nxt=0
|
||||
IF IsEmpty() THEN
|
||||
queueFront=node
|
||||
ELSE
|
||||
queueRear.nxt=node
|
||||
FI
|
||||
queueRear=node
|
||||
RETURN
|
||||
|
||||
PTR FUNC Pop()
|
||||
QueueNode POINTER node
|
||||
CHAR ARRAY v
|
||||
|
||||
IF IsEmpty() THEN
|
||||
PrintE("Error: queue is empty!")
|
||||
Break()
|
||||
FI
|
||||
|
||||
node=queueFront
|
||||
v=node.data
|
||||
queueFront=node.nxt
|
||||
Free(node,NODE_SIZE)
|
||||
RETURN (v)
|
||||
|
||||
PROC TestIsEmpty()
|
||||
IF IsEmpty() THEN
|
||||
PrintE("Queue is empty")
|
||||
ELSE
|
||||
PrintE("Queue is not empty")
|
||||
FI
|
||||
RETURN
|
||||
|
||||
PROC TestPush(CHAR ARRAY v)
|
||||
PrintF("Push: %S%E",v)
|
||||
Push(v)
|
||||
RETURN
|
||||
|
||||
PROC TestPop()
|
||||
CHAR ARRAY v
|
||||
|
||||
Print("Pop: ")
|
||||
v=Pop()
|
||||
PrintE(v)
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
AllocInit(0)
|
||||
queueFront=0
|
||||
queueRear=0
|
||||
|
||||
Put(125) PutE() ;clear screen
|
||||
|
||||
TestIsEmpty()
|
||||
TestPush("foo")
|
||||
TestIsEmpty()
|
||||
TestPush("bar")
|
||||
TestPop()
|
||||
TestIsEmpty()
|
||||
TestPush("baz")
|
||||
TestPop()
|
||||
TestIsEmpty()
|
||||
TestPop()
|
||||
TestIsEmpty()
|
||||
TestPop()
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue