Queue Implementation

#include<stdio.h>

void main()
{

    int q[50],front=1,rear=0,ch,size,temp,i;
    printf("Enter the Size of Queue");
    scanf("%d",&size);

    do
    {
        printf("\n 1.ENQUEUE\n 2.DEQUEUE\n 3.Display\n4.Exit");
        printf("\n Enter your choice");
        scanf("%d",&ch);

        switch(ch)
        {
        case 1:
            if(rear<=size)
            {
                ++rear;
                printf("\nEnter the Queue value");
                scanf("%d",&q[rear]);
            }
            else
                printf("\nQueue is full");
            break;

        case 2:
            if(rear==0)
                printf("\n Queue is empty");
            else
            {
                temp=q[front];
                printf("\nDeleted Item=%d",temp);
                ++front;

            }
            break;
        case 3:
            printf("\nQueue order: ");
                for(i=front;i<=rear;i++)
                    printf("\t%d",q[i]);
                    break;
        case 4:
            exit(0);

        default:
            printf("\nWrong Choice.... Try again...!!");


        }
    }while(ch!=4);
}

No comments:

Post a Comment

Thank you for using this blog.