Stack and Queue (CompletePsuedoCode)
Stack and Queue (CompletePsuedoCode)
CREATING A STACK
PUSH
PROCEDURE Push(Value : INTEGER)
IF Top<=Max
TopßTop+1
Stack[Top]ßValue
ELSE
OUTPUT “The Stack is Full”
END IF
POP
FUNCTION Pop() RETURN INTEGER
DECLARE Popped : INTEGER
IF Top<>-1
PoppedßStack[Top]
TopßTop-1
ELSE
OUTPUT “The Stack is Full”
PoppedßNull
END IF
RETURN Popped
END FUNCTION
QUEUE
Adding to Queue
PROCEDURE NQ(Value : INTEGER)
IF Free>0
EndßEnd+1
IF Free=7
StartßStart+1
END IF
IF End>6
Endß0
END IF
Q[End]ßValue
FreeßFree-1
ELSE
OUTPUT “The Queue is full”
END IF
END IF
Removing the Queue
FUNCTION DQ() RETURN INTEGER
DECLARE Removed : INTEGER
IF Free<7 //there is something to remove
RemovedßQ[Start]
FreeßFree+1
IF Free=7
Start,End ß Null
END IF
StartßStart+1
IF Start>6 /// for wrap around
Startß0
END IF
ELSE
OUTPUT “The Queue is empty”
RemovedßNull
END IF
RETURN Removed
END FUNCTION