UrbanPro
true

Take BTech Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Circular Queue

B
Balaji K
16/11/2020 0 0

#include <stdio.h>

#include <stdlib.h>

#define MAX 5

char a[MAX];

int front = 0, rear = -1, count = 0;

 

void insert()

{

  char item;

if(count==MAX)

{

   printf("\n\t\tCircular Queue Overflow");

   return;

   }

   else

   {

   printf("\n\t Enter the Element: ");

   scanf("%s",&item);

   rear=(rear+1)%MAX;

   a[rear] = item;

   count = count + 1;

   }

   }

 

   void del()

   {

   char item;

   if(count == 0)

   {

      printf("\n\t\tCircular Queue Underflow");

      return;

    }

   else

   {

   item = a[front];

   front = (front+1)%MAX;

   count = count - 1;

   printf("\n\tDeleted Item = %c",item);

   }

   }

 

 

   void display()

   {

   int i,j=front;

   if(count == 0)

     {

     printf("\n\t\tCircular Queue is Empty");

     return;

     }

   else

   {

   printf("\n\tFront = %d  Rear = %d  Count = %d\n",front,rear,count);

   printf("\n\tCircular Queue Elements are: \n\n");

    for(i=1;i<=count;i++)

   {

     printf("\t%d",j);

     j = (j+1)%MAX;

     }

   printf("\n");

   j = front;

   for(i=1;i<=count;i++)

   {

     printf("\t%c",a[j]);

     j = (j+1)%MAX;

     }

     }

     }

 

     int main()

     {

     int ch;

     do

     {

     printf("\n\n\t\tCircular Queue\n\n");

     printf("\t<1> Insert\n");

     printf("\t<2> Delete\n");

     printf("\t<3> Display\n");

     printf("\t<4> Exit\n\n");

     printf("\t    Enter Your Choice: ");

     scanf("%d",&ch);

     switch(ch)

     {

     case 1: insert();

             display();

             break;

 

     case 2: del();

             display();

             break;

     case 3: display();

             break;

     case 4: exit(0);

 

     default: printf("\n\tInvalid Choice")                          ;

              break;

     }

     } while(ch!=5);

     return 0;

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

C program for Beginners
A Program to print 2 integer value. #include<stdio.h> #include<conio.h> main() int a,b,add; a=5; b=3; add=a+b; printf(“ Addition=%d”,&add); getch(); Brief description...
P

Quick Sort Algorithm
Choose the pivot (using the "median-of-three" technique); also, put the smallest of the 3 values in A, put the largest of the 3 values in A, and swap the pivot with the value in A. (Putting the smallest...

Understanding Asymptotic Notations And Big Oh(O)
What are asymptotic notations for complexity analysis?A problem may have numerous algorithmic solutions. In order to choose the best algorithm for a particular task, you need to be able to judge how long...

Spring - Dependency Injection (DI)
Spring - Dependency Injection (DI) DI is a framework which provides loose coupling in code. Here loose coupling means no hard coding of the object. Instead of hard coding, we will be injecting these object...

Introductory Discussions On Complexity Analysis
What is Complexity Analysis of Algorithm? Complexity Analysis, simply put, is a technique through which you can judge about how good one particular algorithm is. Now the term “good” can mean...
X

Looking for BTech Tuition Classes?

The best tutors for BTech Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take BTech Tuition with the Best Tutors

The best Tutors for BTech Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more