say an array of size 30.....

let i,j,k  be the top of 3 stacks respectively and p,q,r be the bottom
of 3 stacks...

divide the array into 3 equal parts...

Initially,
s1-  0-9........... i and p points to 9
s2 - 10-19.......j and q points to 19
s3 - 20-29.......k and r points to 29

...if you push in s1  perform, i--....and if u pop, perform i++...and
similarly for all....

to handle stack overflow ..i.e. to use entire array efficiently

..say we r pushing in s2 and when j reaches 10 ...if space is
available in s1....shift the array elements of s1 to left and reset
new position for i and p

...now if both s1 and s2 are full and if we want to still push in s2
and if s3 is free

then shift array elements of s2 to right ..and reset j and q...

..similary do for other stacks...

..hope this will do :)

On Jun 3, 12:31 pm, sunny agrawal <sunny816.i...@gmail.com> wrote:
>  @Harshal
> Your Solution is optimal but i think in this question whenever there is some
> space available in array we should be able to use that space for either of
> the stack.
> in your solution this thing is missing. I don't know the solution but i
> think it can be improved in a way to get the required
>
>
>
>
>
>
>
>
>
> On Fri, Jun 3, 2011 at 12:31 PM, Harshal <hc4...@gmail.com> wrote:
> > Divide the array into 3 equal parts and allow each stack to grow in its
> > space (1/3 of total.)
>
> > On Fri, Jun 3, 2011 at 11:54 AM, kumar vr <kumarg...@gmail.com> wrote:
>
> >> Can you give an efficient way of implementing 3 stacks using  a single
> >> array?
>
> >>  --
> >> 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.
>
> > --
> > Harshal Choudhary,
> > III Year B.Tech CSE,
> > NIT Surathkal, Karnataka, 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.
>
> --
> Sunny Aggrawal
> B-Tech IV year,CSI
> Indian Institute Of Technology,Roorkee

-- 
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.

Reply via email to