Sample Video Frame

Created by Zed A. Shaw Updated 2024-12-10 18:57:40
 

Exercise 33: Linked List Algorithms

I'm going to cover two algorithms for a linked list that involve sorting. I'm going to warn you first that if you need to sort the data, then don't use a linked list. These are horrible for sorting things, and there are much better data structures you can use if that's a requirement. I'm covering these two algorithms because they are slightly difficult to pull off with a linked list, and get you thinking about how to efficently manipulate them.

In the interest of writing this book, I'm going to put the algorithms in two different files list_algos.h and list_algos.c then write a test in list_algos_test.c. For now, just follow my structure, since it keeps things clean, but if you ever work on other libraries, remember that this isn't a common structure.

In this exercise, I'm also going to give you an extra challenge and I want you to try not to cheat. I'm going to give you the unit test first, and I want you to type it in. Then, I want you to try and implement the two algorithms based on their descriptions in Wikipedia before seeing if your code looks like my code.

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.