data-structures · intermediate · ~15 min

BST inorder to array

Recursive tree traversal that produces output.

Challenge

Given the same bst_t as the previous exercise, implement void bst_inorder(const bst_t *root, int *out, size_t *idx) that appends values in ascending order to out[*idx], advancing *idx.

Starter code

#include <stddef.h>

void bst_inorder(const bst_t *root, int *out, size_t *idx) {
    /* TODO */
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.