Stack
A stack is a non primitive type. It is an order list in which addition of new data item and deletion of old data item one end known as top of step (TOS) As all the deletion insertion in a is done from top of step the last added element will be the first two be remove from the step. That is the reason why stack is also called last in first out type of list example-
To goes on increasing conversivly a the top most element of stack is remove the stack top is decrement for example.
Stack Implementation
Stack implementation through a very simple technique but is not a flexible way of creation as the size has to be declared during program design after tag the size cannot been baried.
Dynamic Implementation
it also called linked list representation and uses pointer to implement the stack type data structure.
Operation of Stack
1. PUSH - The process of adding a new element to the top of stack each called PUSH operation. In case the array is full and number new element can been accommodated. It is called stack full condition . This condition is called STACK overflow.
2. POP - The process of delegating an element from the TOP of STACK is called POP operation after every POP operation the STACK is determined by one. If there is no on the STACK and the POP is perform. this will result into.
Algorithm for PUSH and POP
Inserting an element (PUSH)
1. [STACK already filled?]
If TOP = MAXSTK, then print:OVERFLOW and return.
2. Set TOP = TOP+1 [Increase TOP by 1]
3. Set STACK [TOP] = ITEM
4. Return.
Algorithm for POP ( STACK, TOP, ITEM) Deleting an array from POP
1. [STACK has an element to be removed]
If TOP = 0 then Print : Overflow and return.
2. Set ITEM = STACK [TOP]
3. Set TOP : TOP-1
4. Return.
Comments
Post a Comment