I guess you can do it using recursion(if allowed). Insert is any way
straight forward(just by pushing onto the stack) but for removal you can do
something like.
remove()
{
topVal = stack.pop();
if(stack.isEmpty())
{
//this is the only element
return topVal
}
// get the last element by recursive call.
retVal = remove();
//push the before one onto the stack back
stack.push(topVal);
return retVal;
}
-Pravin
On Mon, Feb 8, 2010 at 1:49 PM, atul verma <[email protected]> wrote:
> I dont think its possible to implement a queue using a single stack.
>
> Atul
>
>
> On Mon, Feb 8, 2010 at 7:48 AM, MOHIT .... <[email protected]> wrote:
>
>> but question is how to implement using one stack not two S1 and S2
>>
>> --
>> 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.
>
--
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.