blob: c5d59a8242c6409daf6403e75d1b6173ef16ace2 (
plain)
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
|
#include "card_queue.h"
#include <stdlib.h>
void init_queue(struct card_queue *cq)
{
cq->first = NULL;
cq->last = NULL;
}
void push_queue(struct card_queue *cq, const char *str)
{
struct card_queue_item *tmp = malloc(sizeof(struct card_queue_item));
tmp->str = str;
tmp->next = NULL;
if(!cq->first) {
cq->first = tmp;
cq->last = tmp;
} else {
cq->last->next = tmp;
cq->last = tmp;
}
}
struct card_queue_item* get_next_card_from_queue(struct card_queue *cq,
struct card_queue_item *prev)
{
if(prev == NULL)
return cq->first;
else
return prev->next;
}
int is_empty_queue(struct card_queue *cq)
{
return !cq->first;
}
const char* pop_card_queue(struct card_queue *cq)
{
struct card_queue_item *tmp = NULL;
const char *card = NULL;
tmp = cq->first;
cq->first = cq->first->next;
card = tmp->str;
free(tmp);
if(!cq->first)
cq->last = NULL;
return card;
}
int find_out_card_quantity_in_cq(const struct card_queue *cq)
{
int counter = 0;
struct card_queue_item *tmp = cq->first;
while(tmp) {
++counter;
tmp = tmp->next;
}
return counter;
}
void clear_queue(struct card_queue *cq)
{
struct card_queue_item *tmp;
while(cq->first) {
tmp = cq->first;
cq->first = cq->first->next;
free(tmp);
}
cq->first = NULL;
cq->last = NULL;
}
|