It will be good optimisation to keep the elements in second stack
itself after first random access. Maintaining count of elements in
both stack and pop from second stack can result in less number of push
and pop operation for subsequent random access.

On Sat, Jul 23, 2011 at 3:52 PM, ross <[email protected]> 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 <[email protected]> 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
>> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/algogeeks?hl=en.
>
>



-- 
Sanjay Ahuja,
Analyst, Financing Prime Brokerage
Nomura Securities India Pvt. Ltd

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to