0% found this document useful (0 votes)
7 views4 pages

Circular Linked List Program in C

The document describes a program to implement a circular linked list in C. It includes functions to enqueue, dequeue and display elements in the circular queue. The main function uses a switch case to allow the user to choose between enqueue, dequeue and display options.

Uploaded by

gireesha261
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)
7 views4 pages

Circular Linked List Program in C

The document describes a program to implement a circular linked list in C. It includes functions to enqueue, dequeue and display elements in the circular queue. The main function uses a switch case to allow the user to choose between enqueue, dequeue and display options.

Uploaded by

gireesha261
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

Program 7

CIRCULAR LINKED LIST IMPLEMENTATION

AIM: Write a program to implement circular linked list

PROGRAM

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

# define max 6

int queue[max];

int front=-1;

int rear=-1;

void enqueue(int element)

if(front==-1 && rear==-1)

front=0;

rear=0;

queue[rear]=element;

else if((rear+1)%max==front)

printf("Queue is overflow..");

else

rear=(rear+1)%max;

queue[rear]=element;

}
}

void dequeue()

if((front==-1) && (rear==-1))

printf("\nQueue is underflow..");

else if(front==rear)

printf("\nThe dequeued element is %d", queue[front]);

front=-1;

rear=-1;

else

printf("\nThe dequeued element is %d", queue[front]);

front=(front+1)%max;

void display()

int i=front;

if(front==-1 && rear==-1)

printf("\n Queue is empty..");

else

{
printf("\nElements in a Queue are :");

while(i<=rear)

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

i=(i+1)%max;

int main()

int choice=1,x;

clrscr();

while(choice<4 && choice!=0)

printf("\n Press 1: Insert an element");

printf("\nPress 2: Delete an element");

printf("\nPress 3: Display the element\nPress 4 to exit\n");

printf("\nEnter your choice");

scanf("%d", &choice);

switch(choice)

case 1:

printf("Enter the element which is to be inserted");

scanf("%d", &x);

enqueue(x);

break;

case 2:

dequeue();
break;

case 3:

display();

case 4: exit(0);

break;

default: printf("Invalid choice");

}}

return 0;

RESULT: Program to implement circular linked list implemented successfully.

You might also like