typestar

Data structures & algorithms

20 steps in 6 sets of C.

Data structures written out by hand, because in C that is the only way you get them. Sorting and searching, linked lists and stacks, trees and hash tables and heaps, then graphs.

The last set is bit manipulation, which is closer to the metal than anything else here and still turns up in real code more than you would expect. Twenty steps, and it doubles as an algorithms refresher.

Start this tour

Sorting & searching

  • Bubble sortThe sort nobody should use and everybody should have written once.
  • Insertion sortSorting in place by growing a sorted prefix.
  • Binary searchHalve the range each step; a thousand items takes ten comparisons.
  • QuicksortPartition around a pivot, then sort the two halves.
  • Merge sortSplit, sort each half, then merge the two sorted runs.

Lists & stacks

Trees, tables & heaps

Graphs

Bit manipulation

Encore

  • matrix.cMultiply two 3x3 integer matrices and print the result.
  • hash_index.cA word index built on a chained hash table, with counts and a clean teardown.

The other C tours