As we have the standard implementation for the Queue using two stacks, i
think we can use that logic here.
by using the Operating system stack as the second stack, i mean to say using
recursion we can achieve it.

Suppose we call the stack as S1 and it has two functions namely push and
pop, The implementation for the queue interfaces using the single stack is
as follows,

Push_Queue (data x)
{
       S1.push(x)
}

data   Pop_Queue()
{
      if   S1.size == 0
            return underflow
      else if S1.size == 1
            return  S1.pop()
     else
     {
           data x = S1.pop()
           data z = Pop_Queue()
           S1.push(x)
           return z;
     }
}


Please correct me if i am wrong....







On Mon, Feb 8, 2010 at 1:49 PM, atul verma <atul.ii...@gmail.com> 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 .... <mohit...@gmail.com> 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 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