0% found this document useful (0 votes)
3 views

Stack and Queue (CompletePsuedoCode)

The document outlines the implementation of a stack and a queue using arrays in a programming context. It provides procedures for pushing and popping elements in a stack, as well as adding and removing elements in a queue, including handling conditions for full and empty states. Key variables and constants are defined to manage the operations effectively.

Uploaded by

Mazen Zaheer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Stack and Queue (CompletePsuedoCode)

The document outlines the implementation of a stack and a queue using arrays in a programming context. It provides procedures for pushing and popping elements in a stack, as well as adding and removing elements in a queue, including handling conditions for full and empty states. Key variables and constants are defined to manage the operations effectively.

Uploaded by

Mazen Zaheer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

STACKS

CREATING A STACK

DECLARE Stack : ARRAY [0:7] OF INTEGER

DECLARE Top,Max : INTEGER


DECLARE Max ß 7
CONSTANT Null = -1

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

Create the Queue

DECLARE Q : ARRAY[0:6] OF INTEGER


DECLARE Start,End,Free : INTEGER
Freeß7
CONSTANT Null = -1
Start,End ß Null

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

You might also like