Code:
Void push( int data)
1 check tos
2. if tos >= 9
3. print: stack overflow
4 else
5 ++tos // increment tos;
6 store data AA[tos]=data // store data
int pop()
1. check tos
2. if tos<=0
3. print :stack underflow
4. return 0
5. else
6. data= AA[tos] //retrieve data
7. - –tos //decrement tos
8 return data
The above Algorithm is for the stacks in data structure. In the above algorithm you will find that it is been divided into two parts i.e Push and Pop. If you will notice then you will find that the first three steps in both the algorithm are same. Well, now the question arises in your mind how come it is same? Well, this is the basic step to know whether the stack is overflow or not.
Bookmarks