Paper First
Sitting down to write from scratch is a bit humbling. The big-o operations give me a hint about what linked list operations I need to implement – search, access, insert, delete. I did not start in an editor. I started by writing pseudo-code in a notebook. Once I had the pseudo-code with worked tests I moved to Eclipse and started a C project.
Add Tests
I started with insertBeginning and a printList routine. I added a C unit test package, Unity. Looking at the serial output and manually checking the results is not an example of professional. Unity is for embedded C development. It’s lightweight – 1 c file and 2 header files. I’m doing my development in Eclipse with CDT. Copied the test framework files to the project and added the include. That was about all it took to have a working unit test framework installed.
First round I did insertBeginning, insertAfter, deleteBeginning, deleteAfter, and accessAtIndex. It wasn’t a generic implementation. Simple linked list of integers. Next round I pulled the list head out so it would support multiple lists.
Linked List Exercises
Going back to the https://www.geeksforgeeks.org/data-structures/linked-list/ I found questions for the data structure and started working those. So far I’ve added methods to get the length of the list iteratively and recursively. The tests pass. The code isn’t optimized, but the tests pass.
Here’s a link to the repo in case you’re interested: https://github.com/danaspisak/c-refresh/. I stuffed the code in to a simple directory structure, but I lost the build parts. This is an opportunity to look at the Ceedling build system. I’ll look at configuring Eclipse to use Ceedling for the build step.