Queue using linked list in c

Queue using linked list in c:
here is the code in cprogramming which implemets Queue using link list.
it has thease functions
printf("\t\t\t\t Implementation of Queue using Linked list  \n\n");
     printf("Enter your choice\n");
     printf("Insertion---->> 1\n");
     printf("Deletion----->> 2\n");
     printf("search------->> 3\n");
     printf("Display------>> 4\n");
     printf("Exit--------->> 0\n");
Source code for Queue using linked list in C programming:-


#include<stdio.h>
#include<stdlib.h>
struct node
{
 int info;
 struct node *next;
};
struct node *front=NULL;
struct node *rear=NULL;
struct node *ptr=NULL;
void insertion();
void deletion();
void searching();
void display();
int main()
{
 while(1)
 {
     int ch;
     printf("\t\t\t\t Implementation of Queue using Linked list  \n\n");
     printf("Enter your choice\n");
     printf("Insertion---->> 1\n");
     printf("Deletion----->> 2\n");
     printf("search------->> 3\n");
     printf("Display------>> 4\n");
     printf("Exit--------->> 0\n");
     printf("\nEnter here:_");
     scanf("%d",&ch);
     switch(ch)
      {
      case 1 :insertion();
              break;
      case 2 :deletion();
              break;
      case 3 :searching();
           break;        
      case 4 :display();
              break;        
      case 0 :return 0;
      default :printf("you have entered wrong choice.please enter a valid choice\n\n\n");
     }
     system("pause");
     system("cls");
    }
 return 0;
}
void insertion()
{
 int x;
 ptr=(struct node *)malloc(1*sizeof(struct node));
 if(ptr==NULL)
 {
  printf("Queue is full\n\n");
  return;
 }
 printf("Enter an integer\n");
 scanf("%d",&x);
 ptr->info=x;
 ptr->next=NULL;
 if(front==NULL && rear==NULL)
 {
  front=ptr;
  rear=ptr;
  return;
 }
 rear->next=ptr;
 rear=ptr;
 return;
}
void deletion()
{
 if(front==NULL && rear==NULL)
 {
  printf("Queue is empty\n\n");
  return;
 }
 if(rear==front)
 {
  printf("%d is successfully deleted fron Queue\n\n",front->info);
  rear=NULL;
  front=NULL;
  return;
 }
 printf("%d is successfully deleted fron Queue\n\n",front->info);
 front=front->next;
 return;
}
void display()
{
 struct node *loc=NULL;
 if(front==NULL && rear==NULL)
 {
  printf("queue is enpty\n\n");
  return;
 }
 printf("Total elements are-->>");
 for(loc=front;loc!=NULL;loc=loc->next)
 {
  printf(" %d ,",loc->info);
 }
 printf("\n\n");
 return;
}
void searching()
{
 struct node *loc=NULL;
 int x,count=0;
 if(front==NULL && rear==NULL)
 {
  printf("queue is enpty\n\n");
  return;
 }
 printf("Enter your seach key\n");
 scanf("%d",&x);
 for(loc=front;loc!=NULL;loc=loc->next)
 {
  if(loc->info==x)
  {
   printf("%d is found at index %d\n\n",x,count);
   return;
  }
  count++;
 }
 printf(" %d is not found\n\n",x);
 return;
}


The output of the program of Queue using Linked List:-



Final Word:-

In this article, We have shown you about the "How to implement Queue using linked list in c ".We hope you like it

If This post helps you a little bit then please share this post with your friends. For more Computer and programming Related Tips and tricks, please

Follow us on Instagram
Follow us on Facebook
Subscribe us on Youtube
Follow us on Pinterest

Don't forget to share how you like this Content in the comment below. If you have any doubt or suggestion then please write in the comment section below, we will love to hear from you.

                               Thank you.

                                        ( नमस्ते )

                                     🙏 

No comments:

Powered by Blogger.