-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
76 lines (63 loc) · 1.09 KB
/
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
#include <stdlib.h>
#include <stdio.h>
// Queue
typedef struct item item;
typedef item *itp;
typedef struct item {
int data;
itp next;
} item;
int is_empty(itp head){
if (head == NULL){
return 1;
}
return 0;
}
int size(itp head){
int cnt=0;
if (head != NULL){
while (head->next != NULL){
cnt ++;
head = head->next;
}
return cnt +1;
}
else{
return 0;
}
}
void enqueue(itp *head,int dt){
itp p,q;
p = malloc(sizeof(item));
if (p == NULL){
printf("Erorr: can't allocat addr");
}
p->data = dt;
p->next = NULL;
if ((*head) == NULL ){
*head = p;
}
else{
q = *head;
while ((q->next) != NULL){
q = q->next;
}
q->next= p;
}
}
int dequeue(itp *head){
itp p ;
int val;
if (*head != NULL){
p = (*head)->next;
}
val = (*head)->data;
free(*head);
*head = p;
return val;
}
int del(itp *head){
itp p = *head;
*head = (*head)->next;
free(p);
}