0% found this document useful (0 votes)
20 views

p11(Circular Queue Using Linked List)

Uploaded by

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

p11(Circular Queue Using Linked List)

Uploaded by

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

/*CIRCULAR QUEUE USING LINKED LIST*/

#include<stdio.h>

#include<stdlib.h>

struct queue

int info;

struct queue *link;

};

struct queue *front= NULL, *rear = NULL;

void QInsert(int item)

struct queue *new_node;

new_node = (struct queue*)malloc(sizeof(struct queue));

new_node-> info = item;

new_node-> link = NULL;

if(front==NULL && rear == NULL)

front = rear = new_node;

rear -> link = front;

else

rear -> link = new_node;

rear =new_node;

rear -> link = front;

void QDelete()

struct queue *ptr;

ptr=front;
if(front == NULL && rear == NULL)

printf("\n Queue is Empty");

else

if(front == rear)

front=rear=NULL;

printf("\n The value being deleted is : %d", ptr -> info);

free (ptr);

else

front=front->link;

rear->link=front;

printf("\n The value being deleted is: %d", ptr -> info);

free (ptr);

void Display()

struct queue *ptr; ptr = front;

if(front == NULL && rear == NULL)

printf("\n Queue is Empty");

else

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

do
{

printf("%d ", ptr -> info);

ptr = ptr -> link;

}while(ptr != front);

void main()

int val, choice;

do

printf("\n *****MAIN MENU*****");

printf("\n 1. Insert");

printf("\n 2. Delete");

printf("\n 3. Display");

printf("\n 4. Exit");

printf("\n Enter your option: ");

scanf("%d", &choice);

switch(choice)

case 1:
printf("\n Enter the number to insert into Queue : "); scanf("%d", &val);
QInsert(val);
break;
case 2:
QDelete();
break;
case 3:
Display();
break;
}

}while (choice!=4);

}
OUTPUT

You might also like