Exercise 34. Dynamic Array

This is an array that grows on its own and has most of the same features as a linked list. It will usually take up less space, run faster, and has other beneficial properties. This exercise will cover a few of the disadvantages, like very slow removal from the front, with a solution to just do it at the end.

A dynamic array is simply an array of void ** pointers that’s pre-allocated in one shot and that point at the data. In the linked list, you had a full structure that stored the void *value pointer, but in a dynamic array, there’s just a single array with all of them. This means you don’t need any other pointers for next and previous records since you can just index into the dynamic array directly.

To start, I’ll ...

Get Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.