more topic chapters

Stacks

Psuedocode

//This is the push function to add items

PROCEDURE PUSH(Top,Stack)
   StackSize←LENGTH(Stack)-1
   IF Top=StackSize
      THEN
        OUTPUT "Stack is full"
      ELSE
        Top←Top+1
        INPUT Value
        Stack[Top]←Value
   END IF

END PROCEDURE

// This Function is the REMOVE / POP
//We assume the stack is filled or not and the Pointer is pointing to the top
FUNCTION POP(Top,Stack) RETURNS INTEGER
   IF TOP=-1 
     THEN 
       OUTPUT "Stack is empty" 
     ELSE
       Value=Stack[TOP]  
       TOP←Top-1
       RETURN Value
END Function

//Initialising the Stack
DECLARE Stack:ARRAY[1:X] OF INTEGER
//TOP is always 1 less than the lowest value in the array index
TOP←0	  

	   

Python Algorithm

The code is in python for this algorithm

The code is free for anyone to copy and use...The copied code must have the same code and indentation as above

Try it yourself





Download Py