diff options
Diffstat (limited to 'misc/examples/queue.c')
| -rw-r--r-- | misc/examples/queue.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/misc/examples/queue.c b/misc/examples/queue.c index 4064cc77..0f387d52 100644 --- a/misc/examples/queue.c +++ b/misc/examples/queue.c @@ -11,21 +11,22 @@ int main() { stc64_t rng = stc64_new(1234); dist = stc64_uniform_new(0, n); - c_auto (cqueue_i, queue) - { - // Push ten million random numbers onto the queue. - c_forrange (n) - cqueue_i_push(&queue, (int)stc64_uniform(&rng, &dist)); + cqueue_i queue = {0}; - // Push or pop on the queue ten million times - printf("%d\n", n); - c_forrange (n) { // forrange uses initial n only. - int r = (int)stc64_uniform(&rng, &dist); - if (r & 1) - ++n, cqueue_i_push(&queue, r); - else - --n, cqueue_i_pop(&queue); - } - printf("%d, %" c_ZI "\n", n, cqueue_i_size(&queue)); + // Push ten million random numbers onto the queue. + c_forrange (n) + cqueue_i_push(&queue, (int)stc64_uniform(&rng, &dist)); + + // Push or pop on the queue ten million times + printf("%d\n", n); + c_forrange (n) { // forrange uses initial n only. + int r = (int)stc64_uniform(&rng, &dist); + if (r & 1) + ++n, cqueue_i_push(&queue, r); + else + --n, cqueue_i_pop(&queue); } + printf("%d, %" c_ZI "\n", n, cqueue_i_size(&queue)); + + cqueue_i_drop(&queue); } |
