-
Notifications
You must be signed in to change notification settings - Fork 1
/
Queue_linlist.c
65 lines (59 loc) · 1.17 KB
/
Queue_linlist.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
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* next;
};
struct Node* head=NULL;
void enqueue(int val){
struct Node* temp;
struct Node* p;
temp = (struct Node*)malloc(sizeof(struct Node));
temp->data = val;
temp->next=NULL;
if (head==NULL)
{
head=temp;
}
else
{
p=head;
while (p->next!=NULL)
{
p=p->next;
}
p->next=temp;
}
}
int dequeue(){
struct Node* ptr;
ptr=head;
head=head->next;
int val = ptr->data;
free(ptr);
return val;
}
void linklisttreversal(struct Node *ptr)
{
while (ptr != NULL)
{
printf("%d->", ptr->data);
ptr = ptr->next;
}
printf("NULL");
}
int main()
{
enqueue(14);
enqueue(144);
enqueue(1444);
enqueue(12);
printf("element is : %d\n",dequeue());
enqueue(34);
printf("element is : %d\n",dequeue());
printf("element is : %d\n",dequeue());
printf("element is : %d\n",dequeue());
linklisttreversal(head);
return 0;
}