-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab14(queue_usingLL).c
94 lines (91 loc) · 1.93 KB
/
lab14(queue_usingLL).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
93
94
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 3
struct node
{
int data;
struct node *next;
}*newnode,*front,*rear,*temp;
int count = 0;
void enQueue(int a){
newnode = (struct node *)malloc(sizeof(struct node));
newnode->data = a;
if (count == MAX_SIZE) //checking the full condition
{
printf("queue full..");
}
else if (front == NULL)
{
front = newnode;
rear = newnode;
newnode->next = NULL;
count++; //to check whether the stack has reached to the MAX_SIZE
printf("node enQueued successfully..");
}
else{
newnode->next = front;
front = newnode;
count++;
printf("node enQueued successfully..");
}
}
void deQueue(){
if (front == NULL)
{
printf("nothing here to delete...");
}
temp = front;
if (front == rear)
{
front = NULL;
rear = NULL;
}
while (temp->next != rear)
{
temp = temp->next;
}
temp->next = NULL;
free(rear);
rear = temp;
printf("node deQueued succesfully");
}
void traverse(){
if (front == NULL)
{
printf("nothing here to display..");
}
else{
temp = front;
while (temp->next!=NULL)
{
printf("%d -> ",temp->data);
temp = temp->next;
}
printf("%d",temp->data);
}
}
void main(){
int ch,data;
do{
printf("\n1.enQueue\n2.deQueue\n3.Traverse\n");
scanf("%d",&ch);
switch (ch)
{
case 1:
printf("enter the number : ");
scanf("%d",&data);
enQueue(data);
break;
case 2:
deQueue();
break;
case 3:
traverse();
break;
default:
break;
}
printf("\ndo you want to continue (0/1) : ");
scanf("%d",&ch);
}while(ch!=0);
}