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

struct list_t
{
    int *data;
    size_t size;
};

void append(struct list_t *self, int v)
{
    if (!self->data)
        self->data = (int *)malloc(sizeof(int));
    else
        self->data = (int *)realloc(self->data, (self->size + 1) * sizeof(int));

    self->data[self->size - 1] = v;
    self->size += 1;
}

void preorder(struct TreeNode *root, struct list_t *list)
{
    if (!root)
        return;
    append(list, root->val);
    preorder(root->left, list);
    preorder(root->right, list);
}

int *preorderTraversal(struct TreeNode *root, int *returnSize)
{
    struct list_t l = {NULL, 0};

    preorder(root, &l);

    *returnSize = l.size;
    return l.data;
}

int main()
{
    return 0;
}
