@Sunny: yes, you are right.

 If any stack is allowed to grow as long as there is any free space in the
array, we will have to allocate space to stacks sequentially in the array
maintaining a pointer to the previous top element of a particular stack, and
updating the new top.
Thus any new element in a stack will keep a pointer 'prev'.

However, we face a problem of unused space on deleting an element.
The deleted elements may not necessarily appear at the end of the ar-
ray. To cope with this, we can maintain an array (call it free_array) and
initially the whole array is in free_array. For every push operation, we
would delete an entry from this free_array . On pop, we would simply add the
index of popped element to the free_array.

On Fri, Jun 3, 2011 at 1:01 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.
>



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

Reply via email to