for 3 stacks we can start Stack 1 with index 0 and fill 0,3,6,... indices
(3n)
and for Stack 2 we can fill indices 1,4,7,... starting at index 1 (3n+1)
and for Stack 3 we can fill indices 2,5,8... starting at index 2 (3n+2)
Ofcourse in this case even if 2 of the stacks are empty the third one will
get maximum size of N/3 where N is sizeof array.
Or we can start 1st stack from starting, 2nd from end and 3rd from the
middle.
I cant think of any other implementation of 3 stacks where you can survive
without shifting the elements and efficiently using the array space.

Comments welcome.

Anurag Sharma
http://anuragsharma-sun.blogspot.com/


On Wed, Jun 2, 2010 at 10:49 AM, Raj N <rajn...@gmail.com> wrote:

> @Gene: Hey can u explain it in more detail with an example taking 3 stacks
>
>
> On Wed, Jun 2, 2010 at 7:38 AM, Gene <gene.ress...@gmail.com> wrote:
>
>> On Jun 1, 2:27 pm, Raj N <rajn...@gmail.com> wrote:
>> > How to implement 3 stacks using the same?
>> >
>> > On Tue, Jun 1, 2010 at 8:59 PM, Sudarshan Reddy M <
>> sudarsha...@gmail.com>wrote:
>> >
>> >
>> >
>> > > Hi,
>> > > the stacks can implemented in the array one is starting at the begin
>> and
>> > > other is starting at the end growing in opposite directions. If the
>> stack
>> > > tops are colloid then there is no space left; means no room for extra
>> > > elemnts.
>> > > Thanks
>> > > Sudarshan.
>> >
>> > > On Tue, Jun 1, 2010 at 2:11 PM, Raj N <rajn...@gmail.com> wrote:
>> >
>> > >> Hi all,
>> > >> Can someone suggest me an efficient way to implement 2 stacks within
>> a
>> > >> single linear array assuming neither of the stack overflows and an
>> > >> entire stack is never shifted to a different location within the
>> array.
>> >
>>
>> Interleave them. If you need N stacks, use A(i), A(i+N), A(i+2N) ...
>> for the i'th stack.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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.

Reply via email to