Data Structures
Data Structures
CATEGORIES
PUSH.
POP.
OPERATIONS ON STACK
• PUSH: The process to insert an element in the stack is
known as push operation
• POP: The process to delete an element from the stack is
known as pop operation
• POINTS TO REMEMBER
• If no element is present in the stack, it is known as “Stack
Empty” or “Stack Underflow”
• If no more space available to insert in the stack, it is
known as “Stack Full” or “stack overflow”
PUSH : It is used to insert items into the stack.
POP: It is used to delete items from stack.
TOP: It represents the current location of data
in stack.
APPLICATIONS OF STACK
• Some of the real-life applications of data structures are discussed below:
• When you visit websites, you will find browser stores the URL of a page in
the stack. After hitting the back button you will see that browser history
will show the most recent URL where you navigated to it.
• When an individual is trying to make changes in a document, the text
editor will store the previous versions in a stack. Hence, when you press the
undo button, the previous version will be restored. This ‘do’ and ‘undo’ of
text editors is done through the data structure.
• The operating system utilizes a stack for keeping track of memory in the
operating systems. After the program is allocated to memory you will see
that the operating system pushes the memory address to the stack.
• By evaluating the arithmetic expressions, you might be able to use a stack
for storing intermediate results or performing necessary calculations in
the right order. Hence, from data structures, you can perform an evaluation
of arithmetic expressions.
• class Stack
• {
• int s[];
• int top;
• int cap;
• Stack(int m)
• {
• cap=m;
• top=-1;
• s=new int[cap];
•
• }
• void push(int x)
• {
• if(top==(cap-1))
• System.out.println("stack is full");
• else
• {
• System.out.println(x+" inserted in the stack memory");
• s[++top]=x;
• }
• }
• void pop()
• {
• if(top==-1)
• System.out.println("stack underflow");
• else
• System.out.println("element removed from stack is"+s[top--]);
• }
• void display()
• {
• System.out.println("elements of stack are");
• for(int i=0;i<=top;i++)
• System.out.println(s[i]);
• }
• void main()
• {
• push(10);
• push(20);
• display();
• }
• }