-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB11.C
More file actions
141 lines (104 loc) · 1.82 KB
/
LAB11.C
File metadata and controls
141 lines (104 loc) · 1.82 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Linked list as Q implementation is quite
// simple and easy to implement
// insert operation is nothing but adding@rear
// delete operation is delete@front
#include<alloc.h>
#define MAX 5
struct node
{
int data;
struct node *link;
};
struct node * getnode()
{
return ( struct node *) malloc( sizeof( struct node ));
}
struct node *ins( struct node * , int );
struct node *del( struct node *);
void display( struct node *);
void main( )
{
struct node *H;
int c = 0 , x , choice;
H = NULL;
while(1)
{
clrscr();
printf("1. Insert \n");
printf("2. Delete \n");
printf("3. Display \n");
printf("4. Exit \n");
printf("Choice = ");
scanf("%d", &choice);
switch( choice )
{
case 1:
if( c == MAX )
printf("Q Full\n");
else
{
printf("Enter element= ");
scanf("%d",&x);
H = ins( H , x );
c++;
}
break;
case 2:
if( c == 0 )
printf("Q empty \n");
else
{
H = del( H );
c--;
}
break;
case 3:
if( c == 0 )
printf("OOPS !!!! nothing to display \n");
else
display( H );
break;
case 4:
exit(0);
}
getch();
}
}
struct node *ins( struct node *H , int data)
{
struct node *T;
if( H == NULL )
{
H = getnode();
T = H;
}
else
{
T = H;
while( T->link!=NULL)
T = T->link;
T->link= getnode();
T = T->link;
}
T->data = data;
T->link = NULL;
return H;
}
struct node *del( struct node *H)
{
struct node *T;
printf("Deleted element = %d\n", H->data);
T = H;
H = H->link;
free( T);
return H;
}
void display( struct node *T )
{
printf("Content of the Q \n");
while( T!= NULL)
{
printf("%d\t", T->data);
T =T->link;
}
}