This is code for queue using single stack

#include<stdio.h>
#include<stdlib.h>
#define MAX 30
int stack[MAX],top=-1;
void push(int num)
{
    top++;
    if(top==MAX-1)
    {
        printf("Queue overflow\n");
        exit(0);
    }
        stack[top]=num;
}

int pop()
{
    if(top==-1)
    {
        printf("Queue Underflow\n");
        exit(0);
    }
    return(stack[top--]);
}

int  delete()
{
    int num,num1;
    if(top==0)
    {
        return(pop(stack,top));
    }
        num=pop(stack,top);
    num1=delete(stack,top);
    push(num);
    return(num1);
}

int main()
{
int ch,num;
while(1)
{
    printf("1->insert 2->Delete 3->exit\n");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:scanf("%d",&num);
               push(num);
               printf("Inserted Element: %d\n",num);
               break;
        case 2:printf("Deleted element:%d\n",delete());
               break;
        case 3:exit(0);
               break;
    }
}
return(0);
}








----------------------------------------
CHERUVU JAANU REDDY
M.Tech in CSIS


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.

Reply via email to