Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Write a program that uses func ons to perform the following opera ons on circular linked

list.

i) Crea on

ii) Inser on

iii) Dele on

iv) Traversal

PROGRAM:

#include <stdio.h>

#include <stdlib.h>

struct node

int data;

struct node *next;

};

struct node *front=NULL,*rear=NULL,*temp;

void enque(int data);

void search(int key);

void deque();

void display();

void main()

int no,ch,e;

prin ("\n 1 - insert\n 2 - delete \n 3 - Dipslay\n 4 - search\n 5 - Exit");


while (1)

prin ("\n Enter choice : ");

scanf("%d",&ch);

switch (ch)

case 1:

prin ("Enter data : ");

scanf("%d",&no);

enque(no);

break;

case 2:

deque();

break;

case 3:display();

break;

case 4:prin ("enter search element");

scanf("%d",&no);

search(no);

break;

case 5:exit(0);

void enque(int d)
{

temp =(struct node *)malloc(sizeof(struct node));

temp->data = d;

temp->next=NULL;

if (rear == NULL)

front = temp;

rear=temp;

return;

rear->next=temp;

rear=temp;

void display()

temp = front;

if (front == NULL)

prin ("Queue is empty");

return;

while (temp != NULL)

prin ("%d ", temp->data);


temp = temp->next;

void deque()

if (front==NULL)

prin ("\n Error : Trying to delete from empty queue");

return;

front=front->next;

void search(int key)

temp=front;

while(temp!=NULL)

if(temp->data==key)

prin ("element found");

return;

temp=temp->next;

}
prin ("element not found");

OUTPUT:

1 - insert

2 - delete

3 - Dipslay

4 - search

5 - Exit

Enter choice : 1

Enter data : 12

Enter choice : 1

Enter data : 23

Enter choice : 1

Enter data : 34

Enter choice : 3

12 23 34

Enter choice : 2

Enter choice : 3

23 34
Enter choice : 4

enter search element23

element found

Enter choice : 5

You might also like