Upcoming SlideShare
×

# Stack Data Structure & It's Application

25,351 views

Published on

Published in: Education, Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No

Are you sure you want to  Yes  No
• thanks

Are you sure you want to  Yes  No
• nt bd

Are you sure you want to  Yes  No

### Stack Data Structure & It's Application

1. 1. Stack Applications
2. 2. What is stack ? Stack is a special type of data structure. Compared to a container. Last In First Out.
3. 3. What is push ? Inserting a element into stack.
4. 4. What is stack overflow ? Pushing elements when stack is full. When top exceeds size of stack .
5. 5. Algorithm pushProcedure Push (Value)If TOP is equal to MAXOutput an error that the Stack is fullElseAdd 1 to TOPPut data in Value into TOP positionEnd IfEnd Procedure
6. 6. What is pop ? Removing the top element from the stack.
7. 7. What is stack underflow ? Performing pop operation when a stack is empty. When top equals zero.
8. 8. Algorithm popProcedure PopIf TOP is equal to Zero thenStack is empty “Underflow”ElseOutput value from Stack at TOP positionSubtract 1 from TOPEnd IfEnd Procedure
9. 9. Stack Applications
10. 10. Applications of stack Start up & Shut down. Function calling. Argument passing in c.
11. 11. System Startup
12. 12. System Shutdown
13. 13. Function calling
14. 14. void three(){printf("Three startedn");printf("Three endedn");}void two(){printf("Two startedn");three();printf("Two endedn");}void one(){printf("One startedn");two();printf("One endedn");}void main(){clrscr();printf("Main startedn");one();printf("Main endedn");getch();}
15. 15. OutputMain startedOne startedTwo startedThree startedThree endedTwo endedOne endedMain ended
16. 16. Argument passing in C• Consider the following program :-# include <stdio.h># include <conio.h>void main(){int a=3;clrscr();printf(“%d %d%d%d”,a++,++a,++a,a++);getch();}Expected o/p.3566
17. 17.  Buto/p is 6 6 5 3Because the argument are passed fromright to left in a stack and then sent toprintf function.
18. 18. %d %d Top%d %d 6 Called function ie, printf(…); Here the input is taken from stack 6 So, the data order will be 6 6 5 3. 5 Therefore the o/p will be 6 6 5 3. 3
19. 19. Conclusion Stack is one of the efficient way to implement discipline to system.
20. 20. Thank You.