forked from Anjalitripathi0024/Data-Structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7_Simple_queue_linked.c
More file actions
107 lines (101 loc) · 2.45 KB
/
7_Simple_queue_linked.c
File metadata and controls
107 lines (101 loc) · 2.45 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<stdio.h>
#include<stdlib.h>
struct node
{ int data;
struct node *next;
}*front,*rear,*ptr;
void insert()
{ int dt;
ptr=(struct node *)malloc(sizeof(struct node));
if(ptr==NULL)
{ printf("\n ------------------------------------------------");
printf("\n Overflow !!!");
}
else
{ printf("\n\n Enter Data : ");
scanf("%d",&dt);
ptr->data=dt;
if(front==NULL)
{ front=ptr;
rear=ptr;
front->next=NULL;
rear->next=NULL;
}
else
{ rear->next=ptr;
rear=ptr;
rear->next=NULL;
}
printf("\n ------------------------------------------------");
printf("\n Data inserted successfully.");
}
printf("\n ------------------------------------------------");
}
void deletehead()
{ printf("\n ------------------------------------------------");
if(front==NULL)
{ printf("\n Queue is EMPTY !!!"); }
else
{ ptr=front;
front=front->next;
free(ptr);
printf("\n Deleted successfully.");
}
printf("\n ------------------------------------------------");
}
void displayqueue()
{ int i=1;
ptr=front;
printf("\n ------------------------------------------------");
if(front==NULL)
{ printf("\n Queue is EMPTY !!!"); }
else
{ while(ptr!=NULL)
{ printf("\n Node %d : %d",i,ptr->data);
ptr=ptr->next;
i++;
}
}
printf("\n ------------------------------------------------");
}
int calcount()
{ int i=0;
struct node *ptr;
ptr=front;
if(front==NULL)
{ i=0; }
else
{ while(ptr!=NULL)
{ i++;
ptr=ptr->next;
}
}
return i;
}
int main()
{ int c=0,d,count=0;
do
{ count=calcount();
printf("\n\n \t-: Linked List Queue Menu :-");
printf("\n\n 1. Enter Data ----------");
printf("\n 2. Display Queue | Status |");
printf("\n 3. Delete Head | (%d/NA) |",count);
printf("\n 4. Quit ----------");
printf("\n\n Enter choice number : ");
scanf("%d",&c);
switch(c)
{ case 1 : insert();
break;
case 2 : displayqueue();
break;
case 3 : deletehead();
break;
case 4 : break;
default : printf("\n -------------------------------------------------");
printf("\n Invalid input !!!");
printf("\n -------------------------------------------------");
}
}while(c!=4);
printf("\n\n Press any key to EXIT...");
return 0;
}