Skip to content
Gustav Louw edited this page Jan 13, 2021 · 9 revisions
#include <que.h>

The CTL que, analogous to the STL std::queue, is a container specializing in O(1) push (back) and pop (front) operations. A que can be seen as a simplified deq, and therefor maintains all pointer validity and memory contiguousness properties of a deq.

Example: Storing and Summing Integers

#include <stdlib.h>
#include <stdio.h>

#define P
#define T int
#include <que.h>

int main(void)
{
    que_int a = que_int_init();
    for(int i = 0; i < 16; i++)
        que_int_push(&a, rand() % 1024);
    int sum = 0;
    while(!que_int_empty(&a))
    {
        int* x = que_int_front(&a);
        printf("%d\n", *x);
        sum += *x;
        que_int_pop(&a);
    }
    printf("sum: %d\n", sum);
    que_int_free(&a);
}
gcc test.c -I ctl

Memory ownership rules apply when #define P is omitted - simply declare functions T_free and T_copy, as per usual, where T is the type typedef.

Clone this wiki locally