Sample Video Frame

Created by Zed A. Shaw Updated 2024-11-15 13:50:32
 

Exercise 34: Dynamic Array

This is an array that grows on its own, and have 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 dynamic array directly.

To start, I'll give you the header file you should type in for the implementation:

View Source file liblcthw/src/lcthw/darray.h Only

Previous Lesson Next Lesson

Register for Learn C the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.