C Programming Tutorial

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

void cqinsert();
void cqdelete();
void display();
int n=4,y=0;
int q[4];
int f=-1,r=-1;

void main()
{
int ch;
while(ch!=4)
{
clrscr();
printf(\"********MENU********\\n\");
printf(\"1 for Insert queue\\n\");
printf(\"2 for Delete queue\\n\");
printf(\"3 for Display\\n\");
printf(\"4 for Exit\");
printf(\"\\nEnter ur choice: \");
scanf(\"%d\",&ch);
switch(ch)
{
case 1: cqinsert();
    break;
case 2: cqdelete();
    break;
case 3: display();
    break;
case 4: break;
}
}
}

void cqinsert()
{
int x;
    if(r==n)
    {
    r=0;
    }
    else
    {
    r=r+1;
    }
    if(f==r)
    {
    printf(\"Queue overflow\");
        if(f==0)
        {
        r=n;
        }
        if(f!=0)
        {
        r=r-1;
        }
        getch();
    }
    else
    {
    printf(\"Enter the num:\");
    scanf(\"%d\",&x);
    q[r]=x;
    if(f==-1)
        {
        f=0;
        }
    }
}

void cqdelete()
{

    if(f==-1)
    {
    printf(\"Queue underflow\");
    getch();
    }
    else
    {
        y=q[f];
        if(f==r)
        {
        f=-1;
        r=-1;
        }
        else if(f==n)
        {
        f=0;
        }
        else
        {
        f=f+1;
        }
    }
}

void display()
{
int i;
        if(f<=r)
        {
        for(i=f;i<=r;i++)
            {
            printf(\"%d \",q[i]);
            }
        }
        if(r<f)
        {
        for(i=f;i<=n;i++)
             {
             printf(\"%d \",q[i]);
             }
        for(i=0;i<=r;i++)
             {
             printf(\"%d \",q[i]);
             }
        }

getch();
}

 
 
Didn't find what you were looking for? Find more on Program of circular link list