-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_llist.c
69 lines (69 loc) · 1.21 KB
/
queue_llist.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
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node{
int data;
struct node *ptr;
};
struct node *front=NULL;
struct node *insert()
{
struct node *new_node,*rear;
int num;
printf("\nEnter -1 to stop.");
printf("\nEnter elements in queue: ");
scanf("%d",&num);
while(num!=-1)
{
new_node=(struct node *)malloc(sizeof(struct node));
new_node->data=num;
if(front==NULL)
{
front=new_node;
rear=front;
new_node->ptr=NULL;
}
else
{
rear->ptr=new_node;
rear=rear->ptr;
new_node->ptr=NULL;
}
scanf("%d",&num);
}
return front;
}
struct node *display()
{
struct node *z;
z=front;
printf("\nDisplaying elements after operation: ");
while(z!=NULL)
{
printf("\t%d",z->data);
z=z->ptr;
}
return front;
}
struct node *del()
{
struct node *z;
z=front;
front=front->ptr;
free(z);
return front;
}
int main()
{ int n;
insert();
display();
printf("\nHow many elements you wanna delete? : ");
scanf("%d",&n);
while(n>0)
{
del();
n--;
}
display();
return 0;
}