top of page
Wave
Cactus%20Plant_edited.jpg

QUEUE USING SINGLE 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("|            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;
    while(p!=NULL)
    {
        printf("[%d]->",p->data);
        p=p->next;
    }
    printf("\n\n");
}
node* insertion(node* head)
{
    node *get_node(int );
    node *p,*q;
    int x;
    printf("Enter the value which you wand to insert: ");
    scanf("%d",&x);
    p=get_node(x);
    if(p==NULL)
    {
        printf("Queue is overflow.\n\n");
    }
    else if(head==NULL)
    {
        head=p;
    }
    else
    {
        q=head;
        while(q->next!=NULL)
        {
            q=q->next;
        }
        q->next=p;
    }
    return head;
}
node* deletion(node* head)
{
    node *p;
    if(head==NULL)
    {
        printf("Queue is underflow.\n\n");
        return head;
    }
    p=head;
    head=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