queue program in c | Tech With Code

Implementation of queue program in c programming:-

Before implementing Queue, you should know about what is Queue?

What is Queue?

The queue is a data structure that follows FIFO which means first in first out.

Source Code of Queue Program in C:-

#include<stdio.h>
#define size 100
int queue[size];
int front=-1;
int rear=-1;
void insertion();
void deletion();
void display();
void searching();
int main()
{
 while(1)
 {
     int ch;
     printf("\t\t\t\t Operations on Queue  \n\n");
     printf("Enter your choice\n");
     printf("Insertion---->> 1\n");
     printf("Deletion----->> 2\n");
     printf("Display------>> 3\n");
     printf("Exit--------->> 0\n");
     printf("\nEnter here:_");
     scanf("%d",&ch);
     switch(ch)
      {
      case 1 :insertion();
              break;
      case 2 :deletion();
              break;
      case 3 :display();
              break;     
      case 0 :return 0;
      default :printf("you have entered wrong choice.please enter a valid choice\n\n\n");
     }
    }
 return 0;
}
void insertion()
{
 int sl;
 if(rear == (size-1))
 {
  printf("Queue space is running out... you have to delete first\n");
  return;
 }
 else if(front==-1 && rear==-1)
 {
  rear=0;
  front=0;
 }
 else rear=rear+1;
 printf("Enter an element to be added in Queue\n");
 scanf("%d",&sl);                                      //Taking new element in veriable s1;
 queue[rear]=sl;
 return;
}
void deletion()
{
 if(front==-1 && rear == -1)
 {
  printf("Queue  is empty\n");
  return;
 }
    if(rear==front)
 {
  printf("%d is successfully deleted from Queue\n",queue[front]);
  front=-1;
  rear=-1;
 }
 else
 {
  printf("%d is successfully deleted from Queue\n",queue[front]);
  front=front+1;
  return;
 }

}
void display()
{
 int sl;
 if(front== -1 && rear== -1)
 {
  printf("Queue  is empty\n");
  return;
 }
 else
 {
 
  printf("Total elements are :=> ");
     for(sl=front;sl<=rear;sl++)
     printf("%d ,",queue[sl]);
     printf("\n");
 }
 
}

Output of Queue program in c:-

     

Final Word:-

In this article, We have shown you about the "How to implement a queue in c programming".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.