Friday, May 21, 2010

Write a program to maintain two stacks simulataneously in a single array ...using 'c' not c++?

The conncept behind it is to maintain an array of fixed size and two different pointers to the top of stack each pointing to one stack.Initialize one TOS to the minimum array index and the other to the maximum value of array index.





On pushing a value on to the stack,increment the first TOS by one.if you want to push a value on to the second stack decrement the TOS2 by one.





Do vice-versa for popping.





stop the push process when TOS1 becomes TOS2-1.





Stop popping when the TOS values become less than the values initialized to them.


No comments:

Post a Comment