-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_operations_LinkedList.c
More file actions
91 lines (82 loc) · 1.63 KB
/
Copy pathQueue_operations_LinkedList.c
File metadata and controls
91 lines (82 loc) · 1.63 KB
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
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 10
void enqueue();
void dequeue();
void print();
struct node
{
int data;
struct node* next;
};
struct node* front = NULL;
struct node* rear = NULL;
void enqueue()
{
int enqueue_val = 0;
printf("\nEnter value to enqueue :");
scanf("%d",&enqueue_val);
struct node *newNode = (struct node*)malloc(sizeof(struct node));
newNode -> data = enqueue_val;
newNode -> next = NULL;
if(rear == NULL)
{
front = newNode;
rear = newNode;
}
else
{
rear -> next = newNode;
rear = newNode;
}
}
void dequeue()
{
if(front == NULL)
{
printf("\nQueue is empty!!\n");
return;
}
struct node* temp = front;
front = front -> next;
free(temp);
}
void print()
{
if(front == NULL)
{
printf("\nQueue is empty!!\n");
return;
}
struct node* temp = front;
printf("\nPrinting Queue :\n");
while(temp != NULL)
{
printf("%d\t",temp -> data);
temp = temp -> next;
}
}
void main()
{
int option = 0;
while(option != 4)
{
printf("\nSelect an option:\n1. Enqueue\n2. Dequeue\n3. Print\n4. Exit\n");
scanf("%d",&option);
switch(option)
{
case 1:
enqueue();
break;Previously on my setup, I had seen this crash happen at End Call.
case 2:
dequeue();
break;
case 3:
print();
break;
case 4:
printf("Exiting!!");
exit(0);
}
}
}