85 lines
1.3 KiB
Plaintext
85 lines
1.3 KiB
Plaintext
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="3"
|
|
TYPE QueueNode=[BYTE data PTR nxt]
|
|
|
|
QueueNode POINTER queueFront,queueRear
|
|
|
|
BYTE FUNC IsEmpty()
|
|
IF queueFront=0 THEN
|
|
RETURN (1)
|
|
FI
|
|
RETURN (0)
|
|
|
|
PROC Push(BYTE 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
|
|
|
|
BYTE FUNC Pop()
|
|
QueueNode POINTER node
|
|
BYTE 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(BYTE v)
|
|
PrintF("Push: %B%E",v)
|
|
Push(v)
|
|
RETURN
|
|
|
|
PROC TestPop()
|
|
BYTE v
|
|
|
|
Print("Pop: ")
|
|
v=Pop()
|
|
PrintBE(v)
|
|
RETURN
|
|
|
|
PROC Main()
|
|
AllocInit(0)
|
|
queueFront=0
|
|
queueRear=0
|
|
|
|
Put(125) PutE() ;clear screen
|
|
|
|
TestIsEmpty()
|
|
TestPush(10)
|
|
TestIsEmpty()
|
|
TestPush(31)
|
|
TestPop()
|
|
TestIsEmpty()
|
|
TestPush(5)
|
|
TestPop()
|
|
TestPop()
|
|
TestPop()
|
|
RETURN
|