Skip to content

Latest commit

 

History

History

Binary Search Tree

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Binary Search Tree

Template arguments

T - Type of elements.

Functions

insert

Return type: none
Arguments: T

Inserts a given value to the tree.

search

Return type: bool
Arguments: T

Returns whether a given value exist in the tree.

remove

Return type: none
Arguments: T

Removes given value from the tree if it exist.

Usage

Library include

#include "path/to/Basic-Data-Structures/include/bstree"

BSTree declaration

BSTree<int> l;

Insertion

tree.insert(2);
tree.insert(4);
tree.insert(1);
tree.insert(5);
tree.insert(3);
/*
      now tree looks like this:

        2
       / \
      1   4
         / \
        3   5
*/

Printing

You can print BSTree using BSTreePrinter class. Library include:

#include "path/to/Basic-Data-Structures/include/bstreeprinter"

Available functions:

static void print(BSTree<T>*);
static void print(BSTree<T>&);

Example:

BSTree<int> t;
// some insert operations here
BSTreePrinter<int>::print(t); // tree object passed by reference

or

BSTreePrinter<int>::print(&t); // tree object passed by pointer

Full example code