data structures/algorithm challenge in C