Data Structures Tutorial

c data structures

Data structures are a way of organizing data. Data structures can be used to efficiently:

  • store and retrieve information;
  • search information;
  • keep data ordered;
  • solve problems.

I personally like to divide them into four categories:

  • Lists: Simple Linked List, Double Linked List, Circular List etc;
  • Hashtables: Hashtable, Dictionary, Map etc;
  • Trees: Binary Search Tree, AVL Tree, B Tree, Heap etc;
  • Graphs: Linked List Graph, Matrix Graph etc;
  • Stacks.

The data structures will be implemented in the C programming language. I chose this because it supports pointers and the implementation will contain as little overhead code as possible. Once you learned how to implement C data structures, porting the same code to other languages such as Javascript, Java, PHP should be easy.

The code is compiled using CodeBlocks with MinGW compiler because it’s freeware. You can of course use any other C compiler or IDE such as: Microsoft Visual Studio, C++ Builder etc.

C Data Structures

The below links should be read in order because simpler data structures serve as backing for more complex ones.

C Linked List

  1. Creating a linked list.
  2. Add node to beginning of list.
  3. Inserting a node after a certain position.
  4. Inserting a node before a specified position.
  5. Deleting a node at a certain position.
  6. Deallocating the memory used by the linked list.

Misc tutorials on this topic

Array Data Structure in C/C++

Size of data types in C and C++

Write an array data structure to file in C

Write to file struct containing char pointer

Stack implementation using Arrays in C

Dot (.) vs arrow (->) operator in C