0Pricing
C Academy · Lesson

Tree Nodes and Structure

Model a node with pointers.

What Is a Binary Tree?

A binary tree is a hierarchical structure where each node holds a value and links to up to two children: a left child and a right child.

The topmost node is the root. Nodes with no children are leaves. This shape makes binary trees great for fast search, sorting, and recursive processing.

The Node Struct

In C we model a node with a struct that stores the data plus two self-referential pointers.

Each pointer points to another Node, or to NULL when there is no child on that side.

struct Node {
    int value;
    struct Node *left;
    struct Node *right;
};

All lessons in this course

  1. Tree Nodes and Structure
  2. Inserting into a BST
  3. Traversals
  4. Searching and Freeing
← Back to C Academy