0% found this document useful (0 votes)
3 views7 pages

Circular Queue Implement

The document presents a C program for implementing a circular queue with basic operations such as insertion, deletion, peeking, and displaying elements. It includes functions to check if the queue is empty or full and handles user input for performing these operations in a loop. The program utilizes an array to store queue elements and manages front and rear indices accordingly.

Uploaded by

raajujitesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Circular Queue Implement

The document presents a C program for implementing a circular queue with basic operations such as insertion, deletion, peeking, and displaying elements. It includes functions to check if the queue is empty or full and handles user input for performing these operations in a loop. The program utilizes an array to store queue elements and manages front and rear indices accordingly.

Uploaded by

raajujitesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

EX.NO:5A CIRCULAR QUEUE IMPLEMENTATION R.

JITESHRAAJU_22IT038

Code:

#import <stdio.h>

#import <stdlib.h>//circular queue in book not using structure

#define MAX 10

int cqueue_arr[MAX];

int f=-1;

int r=-1;

void display();

void insert(int item);

int del();

int peek();

int isempty();

int isful();

main()

int choice,item;

while(1)

printf("1.insert\n");

printf("2.Delete\n");

printf("3.peek\n");

printf("4.display\n");

printf("5.quit\n");

printf("enter your choice\n");

scanf("%d",&choice);

switch(choice)

case 1:

printf("Enter element for insertion: \n");

scanf(" %d",&item);
insert(item);

break;

case 2:

printf("Element deleted is %d\n",del());

break;

case 3:

printf("element at front is finded by peek is %d\n",peek());

break;

case 4:

display();

break;

case 5:

exit(1);

default:

printf("wrong choice\n");

void insert(int item)//pssing item value in insert function

if(isfull())//not passing any argument to isfull function

printf("Queue is full\n");

return;

if(f==-1)

{
f=0;

if(r==MAX-1)

r=0;

else

r=r+1;

cqueue_arr[r]=item;

int del()

int val;

if(isempty())

printf("queue is empty\n");

exit(1);

}//after checking isempty immidiately passing to val;

val=cqueue_arr[f];//removing fth index value in array

//for checking for only one element

if(f==r)

f=-1;

r=-1;

else if(f==MAX-1)

f=0;//after removing last value max-1 f is returned to zero


else

f=f+1;

return val;

int isempty()//ONLY CHECKING F IS -1 OR NOT

if(f==-1)

return 1;

else

return 0;

int isfull()

if((f==0 && r==MAX-1) || (f==r+1))

return 1;

else

return 0;

int peek()

{
if(isempty())

printf("Queue is empty\n");

exit(1);

return cqueue_arr[f];

void display()

int i;//declaring i to get value of front

if(isempty())

printf("queue is emprty canot display any elements\n");

return ;

/*printf("Queue elements are: \n");

i=f;//storing f value in i

if(f<=r)

while(i<=r)

printf("%d ",cqueue_arr[i++]);

else

while(i<=MAX-1)

printf("%d ",cqueue_arr[i++]);

i=0;
while(i<=r)

printf("%d ",cqueue_arr[i++]);

printf("\n");*/

//___________________________//

if(f<=r)

for(int i=f;i<=r;i++)

printf("%d ",cqueue_arr[i]);

else

for(int i=f;i<=MAX-1;i++)

printf("%d ",cqueue_arr[i]);

for(int i=0;i<=r;i++)

printf("%d ",cqueue_arr[i]);

printf("\n");

}
OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy