Data Structures Lerax  v3.0-104-ge031
Opinionated Data Structures & Algorithms
Loading...
Searching...
No Matches
bst.h
Go to the documentation of this file.
1
12
13#ifndef BST_H
14#define BST_H
15
21
22// definition of BinaryTree and struct node.
23#include "../binary-tree.h"
24
30typedef struct BinaryNode BSTree;
31
32#ifndef Type
33#define Type BINARY_NODE_TYPE
34#endif
35
36#define BST_EMPTY (BSTree*) 0
37
48
56
65
75
86
94
103
113
123
131
139
147
155
164
173
182
191
201
202#endif
struct BinaryNode BSTree
This module define a Abstract Data Type for the structure Binary Search Tree.
Definition bst.h:30
BSTree * bst_create_node(BSTree *left, BSTree *right, Type value)
Creates a new BST node.
BSTree * bst_create(void)
Creates an empty BST.
int bst_exists(BSTree *t, Type c)
Checks if a value exists in a BST.
BSTree * bst_remove(BSTree *t, Type c)
Removes a value from a BST.
int bst_nodes(BSTree *t)
Counts the number of nodes in a BST.
void bst_infix(BSTree *t)
Prints the elements of a BST in in-order traversal.
int bst_equals(BSTree *t1, BSTree *t2)
Compares two BSTs for equality.
int bst_two_children(BSTree *t)
Counts the number of nodes in a BST that have two children.
int bst_height(BSTree *t)
Returns the height of a BST.
void bst_free(BSTree *t)
Frees the memory allocated for a BST.
void bst_posfix(BSTree *t)
Prints the elements of a BST in post-order traversal.
BSTree * bst_search(BSTree *t, Type c)
Searches for a value in a BST.
int bst_empty(BSTree *t)
Checks if a BST is empty.
int bst_leafs_primes(BSTree *t)
Counts the number of leaf nodes in a BST that are prime numbers.
BSTree * bst_insert(BSTree *t, Type c)
Inserts a value into a BST.
void bst_prefix(BSTree *t)
Prints the elements of a BST in pre-order traversal.
void bst_print(BSTree *t)
Prints the elements of a BST in in-order traversal.
int bst_nodes_equal_height(BSTree *t)
Counts the number of nodes in a BST that have equal branch heights.
#define Type
Definition sort.h:17
A node in a binary tree.
Definition binary-tree.h:29
BINARY_NODE_TYPE value
Definition binary-tree.h:30
struct BinaryNode * left
Definition binary-tree.h:32
struct BinaryNode * right
Definition binary-tree.h:33