Nice question Kamakshi. The person above has given almost a perfect answer.
For example i=3, we will pop the elements one by one from the top of the 1st stack and pushed to the 2nd stack until the value (top - i) is reached. On Sat, Jul 23, 2011 at 3:52 PM, ross <jagadish1...@gmail.com> wrote: > Well. the idea of an array is - given an integer 'i', you should > support RANDOM ACCESS to the ith element in the 1d array. > Since, we have two stacks, if you want to access an ith element ( say, > i = 5 ),pop all the top 4 elements from the 1st stack and push it to > the second stack. > Now, access the 5th element on top of the 1st stack, then, pop the > elements from the 2nd stack back and push them to the 1st stack. > However, access is O(n) due to the inherent property of a stack which > forbids random access! > > > On Jul 23, 2:00 pm, Kamakshii Aggarwal <kamakshi...@gmail.com> wrote: > > consider a language that does no have arrays...but u can define stack > data > > type like > > stack s; > > using pop ,push and other operations on 2 stacks,how can one dimensions > > array can be implemented?? > > > > -- > > Regards, > > Kamakshi > > kamakshi...@gmail.com > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Nikhil Gupta Senior Co-ordinator, Publicity CSI, NSIT Students' Branch NSIT, New Delhi, India -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.