44 lines
756 B
C
44 lines
756 B
C
#include "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] = v;
|
|
self->size += 1;
|
|
}
|
|
|
|
void postorder(struct TreeNode *root, struct list_t *list)
|
|
{
|
|
if (!root)
|
|
return;
|
|
postorder(root->left, list);
|
|
postorder(root->right, list);
|
|
append(list, root->val);
|
|
}
|
|
|
|
int *postorderTraversal(struct TreeNode *root, int *returnSize)
|
|
{
|
|
struct list_t l = {NULL, 0};
|
|
|
|
postorder(root, &l);
|
|
|
|
*returnSize = l.size;
|
|
return l.data;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
return 0;
|
|
}
|