feat(queue): introduce a queue ds, internally this is just a stack...
the only actual difference is a oneline change which makes pushing append instead of prepend the new data.
This commit is contained in:
parent
9daffd4ed1
commit
758edf9d30
4 changed files with 93 additions and 1 deletions
21
test.c
21
test.c
|
|
@ -99,4 +99,25 @@ main(int argc, char *argv[])
|
|||
|
||||
free(stack);
|
||||
);
|
||||
|
||||
test("queue",
|
||||
char *a = "a";
|
||||
char *b = "b";
|
||||
char *c = "c";
|
||||
|
||||
ds_queue_t *queue = ds_queue_init();
|
||||
it("pushes an item", ds_queue_push(queue, a) == 0);
|
||||
it("pops an item", ds_queue_pop(queue) == a);
|
||||
|
||||
ds_queue_push(queue, b);
|
||||
ds_queue_push(queue, c);
|
||||
|
||||
it("peeks ahead", ds_queue_peek(queue, 0) == b);
|
||||
it("peeks past the queue", ds_queue_peek(queue, INT_MAX) == NULL);
|
||||
|
||||
ds_queue_pop(queue);
|
||||
ds_queue_pop(queue);
|
||||
|
||||
free(queue);
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue