stack applications in data structure
TRANSCRIPT
![Page 1: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/1.jpg)
Stack ApplicationsStack Applications
![Page 2: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/2.jpg)
What is stack ?What is stack ?
Stack is a special type of data structure.
Compared to a container.Last In First Out.
![Page 3: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/3.jpg)
What is push ?What is push ?Inserting a element into stack.
![Page 4: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/4.jpg)
What is stack overflow ?What is stack overflow ?Pushing elements when stack is
full.When top exceeds size of stack .
![Page 5: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/5.jpg)
Algorithm pushAlgorithm pushProcedure Push (Value)If TOP is equal to MAX Output an error that the Stack is fullElseAdd 1 to TOPPut data in Value into TOP positionEnd IfEnd Procedure
![Page 6: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/6.jpg)
What is pop ?What is pop ?Removing the top element from
the stack.
![Page 7: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/7.jpg)
What is stack underflow ?What is stack underflow ?Performing pop operation when a
stack is empty.When top equals zero.
![Page 8: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/8.jpg)
Algorithm popAlgorithm popProcedure PopIf TOP is equal to Zero thenStack is empty “Underflow”ElseOutput value from Stack at TOP position Subtract 1 from TOPEnd IfEnd Procedure
![Page 9: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/9.jpg)
Stack Applications
![Page 10: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/10.jpg)
Applications of stackApplications of stack
Start up & Shut down.Function calling.
Argument passing in c.
![Page 11: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/11.jpg)
System StartupSystem Startup
![Page 12: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/12.jpg)
![Page 13: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/13.jpg)
System ShutdownSystem Shutdown
![Page 14: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/14.jpg)
![Page 15: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/15.jpg)
Function callingFunction calling
![Page 16: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/16.jpg)
void three(){printf("Three started\n");printf("Three ended\n");}void two(){printf("Two started\n");three();printf("Two ended\n");}void one(){printf("One started\n");two();printf("One ended\n");}void main(){clrscr();printf("Main started\n");one();printf("Main ended\n");getch();}
![Page 17: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/17.jpg)
OutputOutput
Main startedOne startedTwo startedThree startedThree endedTwo endedOne endedMain ended
![Page 18: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/18.jpg)
Argument passing in CArgument 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.
3 5 6 6
![Page 19: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/19.jpg)
But o/p is 6 6 5 3
Because the argument are passed from
right to left in a stack and then sent to
printf function.
![Page 20: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/20.jpg)
3
5
6
6
%d %d %d %d
Top
Called function ie, printf(…);
Here the input is taken from stack So, the data order will be 6 6 5 3.
Therefore the o/p will be 6 6 5 3.
![Page 21: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/21.jpg)
ConclusionConclusionStack is one of the efficient way
to implement discipline to system.
![Page 22: Stack Applications in Data structure](https://reader035.vdocument.in/reader035/viewer/2022081412/543f5631afaf9feb098b46a2/html5/thumbnails/22.jpg)
Thank You.Thank You.