-
Notifications
You must be signed in to change notification settings - Fork 64
/
dynamic queue.c
79 lines (69 loc) · 1.31 KB
/
dynamic queue.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
#include<stdio.h>
#include<stdlib.h>
typedef struct qt
{
int data;
struct qt *next;
}queue;
//display
void display(queue **f,queue **r)
{
queue *p;
if(*r==NULL)
printf("empty\n");
else
{
for(p=(*f);p!=NULL;p=p->next)
printf("%d-->",p->data);
printf("NULL\n");
}
}
//insertion
void Qinsert(queue **f,queue **r,int x)
{
queue *temp,*p;
temp=(queue *)malloc(sizeof(queue));
temp->data=x;
temp->next=NULL;
if(*r==NULL)
*r=*f=temp;
else
{
(*r)->next=temp;
*r=temp;
}
display(&*f,&*r);
}
int main()
{
queue *f=NULL,*r=NULL;
int choice,x,k;
do{
printf("\n-----menu----");
printf("\n 1.insert\n 2.delete\n 3.display\n 4.size\n 5.exit\n ");
printf("enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter the element to be entered: ");
scanf("%d",&x);
Qinsert(&f,&r,x);
break;
// case 2: Qdelete();
// break;
case 3:
display(&f,&r);
break;
// case 4:
// k=size(*f,*r);
// printf("size is %d\n",k);
// break;
case 5:
printf("exited\n");
break;
default :
printf("invalid choice\n");
}
}while(choice!=5);
}