linked queue algorithm using c/c++


linked queue algorithm using c/c++


#include<stdio.h>
#include<conio.h>

int a[100],front=-1,rear=-1;

void main()
{
                clrscr();
                void iqueue();
                int dqueue();
                void diplayque();
                int n,ind;

                while(1)
                {
                                printf("\n\n\t Perform Task : \n\t 1. Push \n\t 2. Pop \n\t 3. Display \n\t 4. Exit");
                                printf("\n\tEnter your Choices ");
                                scanf("%d",&n);

                                if(n==4)
                                                break;
                                switch(n)
                                {
                                                case 1:
                                                                iqueue();
                                                                break;
                                                case 2:
                                                                ind = dqueue();
                                                                printf("Deleted Value is %d",ind);
                                                                break;
                                                case 3:
                                                                diplayque();
                                                                break;
                                                default:
                                                                break;
                                }
                                getch();
                                clrscr();
                }
}

void iqueue()
{
    int value;
    char c;

    printf("Enter Element of the Queue : ");
    scanf("%d",&value);

    if(rear==99)
                printf("Queue is OverFlow Value Can't inserted.");
    else
    {
                if(rear==-1 && front == -1)
                {
                                rear =0;
                                front=0;
                }
                else
                                rear=rear+1;
                a[rear]=value;
    }
}

int dqueue()
{
                int value;

                if((front==-1 && rear==-1) || (front>rear))
                                printf("Queue Can't Deleted.");
                else
                {
                                value = a[front];
                                front=front+1;
                                return value;
                }
}
void diplayque()
{
                int tot = rear-front+1;
                if(tot >= 0)
                {
                                printf("\n");
                                for(int i=front;i<=rear;i++)
                                                printf("%d,\t",a[i]);
                }
}

Comments

Popular posts from this blog

How to create a custom form in wordpress

My new Jquery Plugin name is krDailog