Logo 
Search:

C Programming Articles

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

Circular Link list

Posted By: Leticia Silva     Category: C Programming     Views: 11019

Program of Circular Link list.

Code for Circular Link list in C Programming

#include<stdio.h>
#include<conio.h>
struct node
{
    int no;
    struct node *next;
    struct node *back;
};
    struct node *head;
    struct node *p;
    struct node *temp;
void main()
{

    int ctr,no;
    char ch;

    void disp();
    void ins();
    void del();
    clrscr();

    head=(struct node*)malloc(sizeof(struct node));
    p=head;

    printf("\nEnter the value::");
    flushall();
    scanf("%d",&head->no);

    printf("\nDo u want to create another node:::");
    flushall();
    scanf("%c",&ch);

    while(ch=='y'||ch=='Y')
    {
        p->next=(struct node*)malloc(sizeof(struct node));
        p=p->next;
        printf("\nEnter the value::");
        flushall();
        scanf("%d",&p->no);

        printf("\nDo u want to create another node:::");
        flushall();
        scanf("%c",&ch);
    }

    p->next=head;

    printf("\n1)Insert\n2)Delete\n3)Display");
    flushall();
    scanf("%d",&no);
    if(no==1)
    {
        ins();
    }

    getch();
}
void disp()
{
    temp=head;
    p=head;

    printf("%d",head->no);
    temp=temp->next;


    while(temp!=head)
    {
        printf("\n%d",temp->no);
        temp=temp->next;
    }
    printf("\n%d",head->no);


}

void ins()
{
    int num,after;
    printf("\n1)Begining\n2)Middle\n3)End");
    flushall();
    scanf("%d",&num);

    temp=(struct node*)malloc(sizeof(struct node));
    printf("\nEnter the value::");
    flushall();
    scanf("%d",&temp->no);

    if(num==1)
    {
        p=head;
        while(p->next!=head)
        {
            p=p->next;
        }

        temp->next=head;
        p->next=temp;
        head=temp;
    }

    if(num==2)
    {
        printf("\nAfter which node u want to insert::");
        flushall();
        scanf("%d",&after);

        p=head;
        while(p->no!=after)
        {
            p=p->next;
        }
        temp->next=p->next;
        p->next=temp;

    }
    if(num==3)
    {
        p=head;
        while(p->next!=head)
        {
            p=p->next;
        }
        temp->next=head;
        p->next=temp;
    }

    disp();

}
void del()
{
    int num,after;
    printf("\n1)Begining\n2)Middle\n3)End");
    flushall();
    scanf("%d",&num);


}
  
Share: 


Didn't find what you were looking for? Find more on Circular Link list Or get search suggestion and latest updates.

Leticia Silva
Leticia Silva author of Circular Link list is from Salvador, Brazil.
 
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!