Array using stack

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • puneetsardana88
    New Member
    • Aug 2009
    • 57

    Array using stack

    Consider a language that does not have arrays but does have
    stacks as a data type.and PUSH POP..are all defined .Show
    how a one dimensional array can be implemented by using two
    stacks.

    I am unable to solve this. Can somebody tell me whats the approach one should follow? I dnt need the code, only approch will suffice.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Each push is an array element. So you access an element by doing the correct number of pops.

    Then you have to push back the elements you popped in getting to your desired element in order to preserve the array. That's where you use the second stack.

    Comment

    Working...