Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

STACKS

A STACK is a linear structure in which items may be added or removed only at one end

STACKS are also called last in first out (LIFO)

A STACK is a list of elements in which an element may be inserted or deleted only at one end , called the

top

of the stack

Elements are removed from a stack in the reverse order of that in


which they were inserted into the stack.

TERMINOLOGY

PUSH term used to insert an element into a stack

POP term used to delete an element from a stack

TOP CONTAINS the location of the top element of the stack

MAXSTK MAXIMUM number of elements that can be held by the stack

IF TOP = 0 OR TOP =NULL IT MEANS STACK IS

EMPTY

IF TOP = MAXSTK IT MEANS STACK IS

FULL

ARRAY REPRESENTATION OF STACKS

PUSH(STACK,TOP,MAXSTK,ITEM) If TOP=MAXSTK then Print OVERFLOW and return Set TOP=TOP+1 Set STACK[TOP]=ITEM RETURN

POP(STACK,TOP,ITEM) If TOP =0 then Print UNDERFLOW and RETURN Set ITEM=STACK[TOP] Set TOP=TOP-1 Return

You might also like