data-structures · intermediate · ~15 min

Merge two sorted arrays

The merge step of mergesort.

Challenge

Implement void merge_sorted(const int *a, size_t na, const int *b, size_t nb, int *out) that writes the merged sorted sequence into out (size na+nb).

Starter code

#include <stddef.h>
void merge_sorted(const int *a, size_t na, const int *b, size_t nb, int *out) { /* TODO */ }

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