STACK
REPRESENTATION

BY- DIGVIJAY SINGH KARAKOTI
WHAT IS STACK?
Stack is the non-linear non-primitive data
structure or an ordered pair of elements.
A Stack is a LIFO stru...
Some real life examples of
Stack
APPLICATIONS OF STACK
 Expression evaluation
 Infix, Prefix and Postfix Notation
 Expression conversion

 Memory Manag...
OPERATIONS PERFORMED IN
STACK
The m or oper at i ons per f or m by
aj
ed
st ack
ar e:
 PU ( ) – Thi s oper at i on i s us...
PUSH OPERATION
This function will add elements/items into
the stack. Whenever we add an element
into the stack the pointer...
PUSH operation on stack is to add values into the stack. Let us
assume that 5 items 30, 20, 25, 10 and 40 are to be placed...
ALGORITHM FOR PUSH
OPERATIONITEM, TOP)
PUSH(MAXSTK,
STEP 1: If TOP = MAXSTK THEN [Stack already
filled?]
Print "OVERFLOW"
...
Program implementation of PUSH
operation
void push()
{ int item;
If(TOP==maxsize-1)
{ printf(“n Stack is full”);
getch();
...
POP OPERATION
This function will delete elements/items
from the stack. Whenever we add an
element into the stack the point...
POP operation on stack is to delete or retrieve values from the
stack. Let us assume that 4 items 15, 12, 10 and 5 are to ...
ALGORITHM FOR POP
OPERATION
POP[STACK,TOP,ITEM]
STEP 1: If TOP=0
Print ”Underflow”
STEP 2: Set ITEM=STACK[TOP]
STEP 3: Set...
Program implementation of POP
operation
int pop()
{ int item;
if(TOP==-1)
{ printf(“n Stack is empty”);
getch();
exit(0);
...
Upcoming SlideShare
Loading in …5
×

Data structure by Digvijay

620 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
620
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Data structure by Digvijay

  1. 1. STACK REPRESENTATION BY- DIGVIJAY SINGH KARAKOTI
  2. 2. WHAT IS STACK? Stack is the non-linear non-primitive data structure or an ordered pair of elements. A Stack is a LIFO structure which follows the principal of “LAST IN FIRST OUT”, which depicts the insertion of last element in the stack and deletion of first element from the stack from one end called “TOP” of the stack.
  3. 3. Some real life examples of Stack
  4. 4. APPLICATIONS OF STACK  Expression evaluation  Infix, Prefix and Postfix Notation  Expression conversion  Memory Management  Recursion
  5. 5. OPERATIONS PERFORMED IN STACK The m or oper at i ons per f or m by aj ed st ack ar e:  PU ( ) – Thi s oper at i on i s used SH t o i nser t t he el em ent i nt o t he st ack. So, i t i s al so know as n “I N TI O ” oper at i on. SER N  PO ) - Thi s oper at i on i s used P( t o del et e or r et r i eve t he el em ent
  6. 6. PUSH OPERATION This function will add elements/items into the stack. Whenever we add an element into the stack the pointer TOP gets incremented as:TOP+1 or TOP++ This is used to show the position of the element in the stack.
  7. 7. PUSH operation on stack is to add values into the stack. Let us assume that 5 items 30, 20, 25, 10 and 40 are to be placed on the stack. The items can be inserted one by one as shown in following figure:-
  8. 8. ALGORITHM FOR PUSH OPERATIONITEM, TOP) PUSH(MAXSTK, STEP 1: If TOP = MAXSTK THEN [Stack already filled?] Print "OVERFLOW" Go to step 4 End if STEP 2: TOP = TOP + 1 [Increase TOP by 1] STEP 3: Set STK[TOP] = ITEM [Insert ITEM in new TOP position]
  9. 9. Program implementation of PUSH operation void push() { int item; If(TOP==maxsize-1) { printf(“n Stack is full”); getch(); exit(0); } else { printf(“n Enter the element to be inserted”); scanf(“%d”, &item); TOP=TOP+1; stack[TOP]=item; } }
  10. 10. POP OPERATION This function will delete elements/items from the stack. Whenever we add an element into the stack the pointer TOP gets decremented as:TOP-1 or TOP-This is used to show the position of the element in the stack
  11. 11. POP operation on stack is to delete or retrieve values from the stack. Let us assume that 4 items 15, 12, 10 and 5 are to be deleted from the stack. The items can be deleted one by one as shown in following figure:- Figure. Deletion operations
  12. 12. ALGORITHM FOR POP OPERATION POP[STACK,TOP,ITEM] STEP 1: If TOP=0 Print ”Underflow” STEP 2: Set ITEM=STACK[TOP] STEP 3: Set TOP=TOP-1 STEP 4: Return
  13. 13. Program implementation of POP operation int pop() { int item; if(TOP==-1) { printf(“n Stack is empty”); getch(); exit(0); } else { item=stack[TOP]; TOP=TOP-1; printf(“n Item deleted is= %d”, item); } return(item); }

×