-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1000-main.c
111 lines (105 loc) · 2 KB
/
1000-main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdlib.h>
#include <stdio.h>
#include "../deck.h"
void print_deck(const deck_node_t *deck)
{
size_t i;
char kinds[4] = {'S', 'H', 'C', 'D'};
i = 0;
while (deck)
{
if (i)
printf(", ");
printf("{%s, %c}", deck->card->value, kinds[deck->card->kind]);
if (i == 12)
printf("\n");
i = (i + 1) % 13;
deck = deck->next;
}
}
deck_node_t *init_deck(const card_t cards[52])
{
deck_node_t *deck;
deck_node_t *node;
size_t i;
i = 52;
deck = NULL;
while (i--)
{
node = malloc(sizeof(*node));
if (!node)
return (NULL);
node->card = &cards[i];
node->next = deck;
node->prev = NULL;
if (deck)
deck->prev = node;
deck = node;
}
return (deck);
}
int main(void)
{
card_t cards[52] = {
{"Jack", CLUB},
{"4", HEART},
{"3", HEART},
{"3", DIAMOND},
{"Queen", HEART},
{"5", HEART},
{"5", SPADE},
{"10", HEART},
{"6", HEART},
{"5", DIAMOND},
{"6", SPADE},
{"9", HEART},
{"7", DIAMOND},
{"Jack", SPADE},
{"Ace", DIAMOND},
{"9", CLUB},
{"Jack", DIAMOND},
{"7", SPADE},
{"King", DIAMOND},
{"10", CLUB},
{"King", SPADE},
{"8", CLUB},
{"9", SPADE},
{"6", CLUB},
{"Ace", CLUB},
{"3", SPADE},
{"8", SPADE},
{"9", DIAMOND},
{"2", HEART},
{"4", DIAMOND},
{"6", DIAMOND},
{"3", CLUB},
{"Queen", CLUB},
{"10", SPADE},
{"8", DIAMOND},
{"8", HEART},
{"Ace", SPADE},
{"Jack", HEART},
{"2", CLUB},
{"4", SPADE},
{"2", SPADE},
{"2", DIAMOND},
{"King", CLUB},
{"Queen", SPADE},
{"Queen", DIAMOND},
{"7", CLUB},
{"7", HEART},
{"5", CLUB},
{"10", DIAMOND},
{"4", CLUB},
{"King", HEART},
{"Ace", HEART},
};
deck_node_t *deck;
deck = init_deck(cards);
print_deck(deck);
printf("\n");
sort_deck(&deck);
printf("\n");
print_deck(deck);
return (0);
}