Skip to main content

Checkpoint: Generic Tagged Sort

Challenge on lesson: Checkpoint: Generic Byte Container

CHALLENGE
Difficulty: advanced+25 XP

Types already in your editor: ``c typedef struct { unsigned char tag; int key; } item_t; /* tag 1 = int-like, 2 = double-like */ ` Implement: 1. void item_sort(item_t *a, size_t n) โ€” insertion sort over the array treating elements as raw bytes (memcpy moves, comparator on key), stable. 2. const char *item_describe(const item_t *v) โ€” returns "int-like" for tag 1, "double-like" for tag 2, NULL otherwise. 3. size_t item_count_tag(const item_t *a, size_t n, unsigned char tag)` โ€” how many carry the tag.

Back to lesson: Checkpoint: Generic Byte Container