Monday, 15 October 2012

Queue with array

Queue with array

#include<conio.h>
#include<stdio.h>
#define N 5

int queue[N]={0};
int qptr=0;
void  main()
{
    int ch=0;
    clrscr();
    while(ch!=5)
    {
        printf("\n\t 2.INSERT");
        printf("\n\t 3.DELETE");
        printf("\n\t 4.DISPLAY");
        printf("\n\t 5.EXIT");
        scanf("%d",&ch);
        if(ch==2)
        {
            ins();
        }
        if(ch==3)
        {
            del();
        }
        if(ch==4)
        {
            dis();
        }
        if(ch==5)
        {
            printf("\n\n\n\n\n\t\t\t THANK U ");
        }
    }
    getch();
}
void ins(void)
{
    int t;
    printf("\n\t NTER A VALUE::: ");
    scanf("%d",&t);
    queue[qptr]=t;
    qptr++;
}


void del(void)
{
    int i,temp,j;
    if(qptr==0)
    {
        printf("\n\t UNDERFLOW ");
    }
    else
    {
        printf("\n\t THE VALUE REMOVED IS:::::: %d",queue[0]);
        for(i=0;j=i+1;j<qptr;)
        {
            queue[i]=queue[j];
            i++;
            j++;
        }
    }
}

No comments:

Post a Comment