Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

72 lines (44 sloc) 2.838 kb
\chapter{Exercise 32: Double Linked Lists}
The purpose of this book is to teach you how your computer really works, and included in that is
how various data structures and algorithms function. Computers by themselves don't do a lot of
useful processing. To make them do useful things you need to structure the data and then
organize processing on these structures. Other programming languages either include libraries
that implement all of these structures, or they have direct syntax for them. C makes you
implement all the data structures you need yourself, which makes it the perfect language to
learn how they actually work.
My goal in teaching you these data structures and these algorithms is to help you do three
things:
\begin{enumerate}
\item Understand what is really going on in Python, Ruby, or JavaScript code like: \verb|data = {"name": "Zed}|
\item Get even better at C code by applying what you know to a set of solved problems using the data structures.
\item Learn a core set of data structures and algorithms so that you are better informed about what ones work best in certain situations.
\end{enumerate}
\section{What Are Data Structures}
The name "data structure" is self-explanatory. It is an organization of data that fits a certain model. Maybe the model is
designed to allow processing the data in a new way. Maybe it's just organized to store it on disk efficiently. In this book
I'll follow a simple pattern for making data structures that works reliably:
\begin{enumerate}
\item Define a struct for the main "outer structure".
\item Define a struct for the contents, usually nodes with links between them.
\item Create functions that operate on these two.
\end{enumerate}
There's other styles of data structures in C, but this pattern works well and is consistent for most data
structures you'll make.
\section{Making Our Library}
For the rest of this book you'll be creating a library that you can use when you're done with this book. This library will
have the following elements:
\begin{enumerate}
\item Header (.h) files for each data structure.
\item Implementation (.c) files for the algorithms.
\item Unit tests that test all of them to make sure they keep working.
\item Documentation we'll autogenerate from the header files.
\end{enumerate}
Rather than mire the book down with long descriptions of how to setup the library, I'm going to just have you check
out a project that I've created to get you started.
TODO: explain how to get the code from learncodethehardway.org and setup git or mercurial to maintain it.
Once you have this checked out you will then use this repository to make your changes and work with the rest
of this book.
\section{A Double Linked List Implementation}
\section{What You Should See}
\section{How To Break It}
\section{Extra Credit}
Jump to Line
Something went wrong with that request. Please try again.