DSA Hacking Club Library
Loading...
Searching...
No Matches
bst.h File Reference

A simple binary search tree (BST) implementation in C. More...

#include <stdbool.h>
Include dependency graph for bst.h:

Go to the source code of this file.

Classes

struct  treenode
 A node in the binary search tree. More...

Typedefs

typedef struct treenode treenode
 A node in the binary search tree.

Functions

treenodecreatenode (int value)
 Creates a new tree node.
void printtree (treenode *root)
 Prints the tree in a structured format.
bool tree_insertnumber (treenode **rootptr, int value)
 Inserts a number into the binary search tree.
bool tree_findnumber (treenode *root, int value)
 Searches for a value in the binary search tree.

Detailed Description

A simple binary search tree (BST) implementation in C.

Author
Date
2025-09-25

This header provides the data structures and function prototypes for creating, inserting, searching, and printing a binary search tree.

Typedef Documentation

◆ treenode

typedef struct treenode treenode

A node in the binary search tree.

Each node stores an integer value and pointers to its left and right children.

Function Documentation

◆ createnode()

treenode * createnode ( int value)

Creates a new tree node.

Parameters
valueThe integer value to store in the node.
Returns
Pointer to the newly allocated node, or NULL on allocation failure.

◆ printtree()

void printtree ( treenode * root)

Prints the tree in a structured format.

This function is mainly for debugging and visualization.

Parameters
rootPointer to the root node of the tree.

◆ tree_findnumber()

bool tree_findnumber ( treenode * root,
int value )

Searches for a value in the binary search tree.

Parameters
rootPointer to the root of the tree.
valueThe value to search for.
Returns
true if the value is found, false otherwise.

◆ tree_insertnumber()

bool tree_insertnumber ( treenode ** rootptr,
int value )

Inserts a number into the binary search tree.

Parameters
rootptrPointer to the root pointer of the tree.
valueThe value to insert.
Returns
true if the insertion was successful, false if the value already exists.