#include "parsing.h"
#include <stdlib.h>

struct queue *enqueue(struct queue *queue, struct node *node) {
    struct queue *new_elt = malloc(sizeof(struct queue));
    if (!new_elt)
        return queue;
    new_elt->node = node;
    new_elt->next = NULL;
    if (!queue) {
        return new_elt;
    }
    struct queue *it = queue;
    while (it->next) {
        it = it->next;
    }
    it->next = new_elt;
    return queue;
}

struct node *dequeue(struct queue **queue) {
    if (!queue || !*queue)
        return NULL;
    struct node *res = (*queue)->node;
    struct queue *temp = *queue;
    *queue = (*queue)->next;
    free(temp);
    return res;
}

void queue_destroy(struct queue *queue) {
    while (queue) {
        dequeue(&queue);
    }
}