diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-22 13:40:21 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-22 13:40:21 +0300 |
| commit | 5b13d9bfa2b14c1231c5b19a9ccffb2d308112e4 (patch) | |
| tree | 635da16ef4652c7b3f06108d8069869940ef52a4 /priority_queue.c | |
| parent | 18acaac228db4b67acd375b6e5989dfbe71e8f2e (diff) | |
Implement 8dir breadth-first-search and some other stuff
Diffstat (limited to 'priority_queue.c')
| -rw-r--r-- | priority_queue.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/priority_queue.c b/priority_queue.c index 472f5c3..d2517a6 100644 --- a/priority_queue.c +++ b/priority_queue.c @@ -12,35 +12,40 @@ PositionPQ *ppq_new(Position pos, size_t priority) { return ppq; } -/* FIXME: this is shitty */ -void ppq_insert(PositionPQ **ppq, Position pos, size_t priority) { +/* FIXME: insted of `return n` introduce some defines with error codes, + * or an enum I don't care */ +int ppq_insert(PositionPQ **ppq, Position pos, size_t priority) { + //printf("Inserting %zu %zu\n", pos.x, pos.y); PositionPQ *start = *ppq; if ((*ppq) == NULL) { (*ppq) = ppq_new(pos, priority); - return; + return 1; } PositionPQ *n = ppq_new(pos, priority); if (start->priority > priority) { n->next = start; start = n; - return; + return 2; } PositionPQ *temp = *ppq; while(temp->next != NULL && temp->next->priority <= priority) { if (temp->pos.x == pos.x && temp->pos.y == pos.y && temp->priority <= priority) { - return; /* pos is already at the start of ppq with a fine priority */ + return 3; /* pos is already in ppq with a fine priority */ } temp = temp->next; } + if (temp->pos.x == pos.x && temp->pos.y == pos.y && temp->priority <= priority) { + return 3; /* pos is already in ppq with a fine priority */ + } n->next = temp->next; temp->next = n; - return; + return 4; } Position ppq_pop(PositionPQ **ppq) { |
