top of page
Wave
Cactus%20Plant_edited.jpg

CIRCULAR QUEUE USING CIRCULAR LINK LIST

#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
    int data;
    struct node *next;
}node;

int main()
{
    node *get_node(int );
    void display(node*);
    node* insertion(node*);
    node* deletion(node* );
    node*head=NULL;
    int ch;
    do
    {
        printf("----------------------------------------------\n");
        printf("|        CIRCULAR QUEUE USING LINK LIST      |\n");
        printf("----------------------------------------------\n");
        printf("|1.Display Queue                             |\n");
        printf("|2.Insertion                                 |\n");
        printf("|3.Deletion                                  |\n");
        printf("|4.Exit from the program                     |\n");
        printf("----------------------------------------------\n");
        printf("Enter your choice: ");
        scanf("%d",&ch);
        printf("\n");
        switch(ch)
        {
            case 1:
                display(head);
                break;
            case 2:
                head=insertion(head);
                break;
            case 3:
                head=deletion(head);
                break;
            case 4:    
                exit(0);
            default :
                printf("Wrong choice...\n\n");    
        }
    }while(1);
    return 1;    
}
node *get_node(int x)
{
    node *p;
    p=(node*)malloc(sizeof (node));
    p->data=x;
    p->next=NULL;
    return p;
}
void display(node*head)
{
    node *p;
    if(head==NULL)
    {
        printf("Queue is underflow.\n\n");
        return;
    }
    p=head->next;
    while(p!=head)
    {
        printf("[%d]->",p->data);
        p=p->next;
    }
    printf("[%d] \n",p->data);    
}
node* insertion(node* head)
{
    node *p;
    int x;
    printf("Enter the element: ");
    scanf("%d",&x);
    p=get_node(x);
    if(p==NULL)
    {
        printf("Queue is overflow.\n\n");
        return head;
    }
    if(head==NULL)
    {
        head=p;
        p->next=p;
    }
    else
    {
        p->next=head->next;
        head->next=p;
        head=p;
    }
    return head;
}
node* deletion(node* head)
{
    node *p;
    if(head==NULL)
    {
        printf("Queue is underflow.\n\n");
        return head;
    }
    p=head->next;
    if(head==p)
        head=NULL;
    else
        head->next=p->next;
    free(p);
    return head;
}

Subscribe Form

Thanks for submitting!

  • Facebook
  • YouTube
  • Instagram
  • Twitter

©2020 by Abhisek Midya ( A18 ). Proudly created with Wix.com

bottom of page