-
Notifications
You must be signed in to change notification settings - Fork 0
/
naked_single_queue.c
64 lines (54 loc) · 1.35 KB
/
naked_single_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
#include "common.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "naked_single_queue.h"
/**
* The head of the tail-queue that holds "naked single" moves.
*/
STAILQ_HEAD(slisthead, naked_single) naked_singles_head = STAILQ_HEAD_INITIALIZER(naked_singles_head);
void initialise_naked_single_queue(void)
{
static bool initialised = false;
if (initialised == false)
{
STAILQ_INIT(&naked_singles_head);
initialised = true;
}
}
void insert_naked_single(size_t row, size_t col)
{
#ifdef KS_SUDOKU_DEBUG
if (row >= TABLE_ORDER_MAX || col >= TABLE_ORDER_MAX)
{
fprintf(stderr, "insert_naked_single: invalid insertion\n"
"row: %zu, col: %zu", row, col);
exit(EXIT_FAILURE);
}
#endif
struct naked_single *n1 = malloc(sizeof(struct naked_single));
n1->row = row; n1->col = col;
STAILQ_INSERT_TAIL(&naked_singles_head, n1, entries);
}
int is_naked_single_available(void)
{
return !STAILQ_EMPTY(&naked_singles_head);
}
struct naked_single *get_first_naked_single(void)
{
return STAILQ_FIRST(&naked_singles_head);
}
void print_naked_singles(void)
{
struct naked_single *curr = STAILQ_FIRST(&naked_singles_head);
while (curr != NULL)
{
printf("%zu\t%zu\n", curr->row, curr->col);
curr = STAILQ_NEXT(curr, entries);
}
}
void remove_first_naked_single(void)
{
STAILQ_REMOVE_HEAD(&naked_singles_head, entries);
}