@jalaj: These were few solutions discussed b4

1. For 3 stacks a efficient algo is not easy to think in a single array ,
yet we can optimise according the usage. For example lets say out of 3 stack
we know the growth of 2nd stack more closely and we know its variations
boundary of 2nd stack more clearly than others two. In such case make stack
2 static giving it its particular location. For the rest two apply same as
implementation of two stack

|   stack2      |-------->1st                     3rd<-----------|
______________________________
____________


for n stacks make n/2 such intervals.
If n is odd, one interval will be for a single stack.

2. for three stacks u can use indices 0 3 6 etc for stack1. 1 4 7 for stack
2 and 2 5 8 etc for stack 3.
now if any of the stack overflows but there is still space in array as other
stacks have few element then now u can grow ur stack in reverse direction as
shown below :

indices of array :       0  1  2  3  4  5  6  7  8  9  10  11 12

contents                  1   2  3  1         1          1              1
                                    /  \
      \
                              top2    top3
     top1
here 1 represents element of stack1 2 for stack 2 and so on.
now if  u want to insert more element in stack 1 it will overflow while 2
and 3 have space so wat u can do now is grow stack 1 in reverse direction.
ie now place elements for stack 1 in index 11 and so now top1 will point to
11 and so on. u can indicate this behaviour of stack1 by using some tag.





On Fri, Jun 11, 2010 at 10:19 PM, jalaj jaiswal
<[email protected]>wrote:

> @raj n
> for 2 stacks its fine can you please tell for 3 stacks ...i'll generalize
> it
>
>
> On Fri, Jun 11, 2010 at 9:32 PM, Anurag Sharma <[email protected]>wrote:
>
>> Is it without having the need to shift elements at all?
>>
>> Anurag Sharma
>>
>>
>> On Fri, Jun 11, 2010 at 3:41 PM, jalaj jaiswal <[email protected]
>> > wrote:
>>
>>> Give an algorithm to implement n stacks in an array... take care of the
>>> empty space too i.e no overflow shld occur if there is eny empty space left
>>> .
>>>
>>>
>>>
>>>
>>> --
>>> With Regards,
>>> Jalaj Jaiswal
>>> +919026283397
>>> B.TECH IT
>>> IIIT ALLAHABAD
>>>
>>> --
>>> 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]<algogeeks%[email protected]>
>>> .
>>> 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 [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> With Regards,
> Jalaj Jaiswal
> +919026283397
> B.TECH IT
> IIIT ALLAHABAD
>
> --
> 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]<algogeeks%[email protected]>
> .
> 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 [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