This blog is exclusively for GCT CSITA students. Contact us at 'gct.csita@gmail.com'.
Wednesday, August 6, 2008
c simple
Explain how to implement two stacks in one array in such a way that neither stack overflows unless the total number of elements in both the stacks together is n. The push operation must run in O(1) time...
consider one array in both end points separate stack pointer named as SP1,SP2 and push any one end (it must be o(1)) if the total element is same for both stack,
___________________________ SP1___________________________SP2 |<.........array[].........>| n elements
2 comments:
consider one array in both end points separate stack pointer named as SP1,SP2 and push any one end (it must be o(1)) if the total element is same for both stack,
___________________________
SP1___________________________SP2
|<.........array[].........>|
n elements
construct 1 stack from array index 0..
construct 2 stack from array index n-1......
Post a Comment