A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle.A stack is a limited access data structure - elements can be added and removed from the stack only at the top. push adds an item to the top of the stack, pop removes the item from the top. A helpful analogy is to think of a stack of books; you can remove only the top book, also you can add a new book on the top.
Primary operations defined on a stack:
PUSH : add an element at the top of the list.
POP : remove the at the top of the list.
Also "IsEmpty()" and IsFull" function, which tests whether a stack is empty or full respectively.
Example :
Practical Example :Think of piles of books kept in a vertical box.
Computer World: During subroutine call.
Application of Stack :
1. Solving Arithmetic Expression.
2. Solving Tower of Hanoi.
3. Reverse a String .
4 Conversion of a infix expression into prefix expression.
Algorithm of the Push Operation :
Visualization of Push Operation :
Algorithm of the Pop Operation :
Please comment if you find any mistake.
Primary operations defined on a stack:
PUSH : add an element at the top of the list.
POP : remove the at the top of the list.
Also "IsEmpty()" and IsFull" function, which tests whether a stack is empty or full respectively.
Example :
Practical Example :Think of piles of books kept in a vertical box.
Computer World: During subroutine call.
Application of Stack :
1. Solving Arithmetic Expression.
2. Solving Tower of Hanoi.
3. Reverse a String .
4 Conversion of a infix expression into prefix expression.
Algorithm of the Push Operation :
Push(item,array,n,top) { if(n>=top) print "The stack is full". else { top=top+1; array[top]=item; } }
Algorithm of the Pop Operation :
Pop(item,array,top) { if (top<0) The print "stack is empty" else { item =array[top]; top=top+1; } }
Visualization of Pop Operation :
This is all about the basics of Stack . Now we will do some programming in other post and then complex programming.Please comment if you find any mistake.
No comments:
Post a Comment