-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircularQueueLinkedList.c
92 lines (88 loc) · 1.72 KB
/
CircularQueueLinkedList.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// main.c
// CircularQueueLinked
//
// Created by Vicky_Jha on 26/11/19.
// Copyright © 2019 test. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
struct cqueueLL
{
int data;
struct cqueueLL *next;
};
struct cqueueLL *front = NULL , *rear = NULL;
void enqueue()
{
struct cqueueLL *temp = (struct cqueueLL*)malloc(sizeof(struct cqueueLL)),store;
printf("Enter the data\n");
scanf("%d",&temp -> data);
temp -> next = NULL;
if(rear == NULL && front == NULL)
{
front = rear = temp;
temp -> next = front;
}
else
{
rear -> next = temp;
temp -> next = front;
rear = temp;
}
}
void dequeue()
{
if ( front == NULL)
{
printf("Queue empty\n");
}
else
{
struct cqueueLL *temp = front ;
front = temp -> next;
free(temp);
}
}
void display()
{
struct cqueueLL *temp = front;
if (front == NULL)
{
printf("queue is empty\n");
}
else
{
while(temp->next != front)
{
printf("%d ",temp -> data);
temp = temp -> next;
}
printf("%d ",rear -> data );
printf("\n");
}
}
int main(int argc, const char * argv[]) {
int ch;
while(1)
{
printf("Enter your choice\n");
scanf("%d",&ch);
switch (ch) {
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(1);
default:printf("Invalid choice\n");
break;
}
}
return 0;
}