Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Program of circular link list

Posted By: Vilmos Fischer     Category: C Programming     Views: 5219

Write a program of circular link list.

Code for Program of circular link list in C Programming

#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;
        }
        elseif(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();
}
  
Share: 

 
 

Didn't find what you were looking for? Find more on Program of circular link list Or get search suggestion and latest updates.

Vilmos Fischer
Vilmos Fischer author of Program of circular link list is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!