Receive integers one by one (in sorted order) and create a binary tree which means the tree heavily leans to the right and ultimately forms a linked list. More...
#include <malloc.h>
#include <string.h>
#include "report.h"
Classes | |
struct | node |
Standard Binary tree data structure to use. More... | |
Typedefs | |
typedef node | NODE |
typedef node * | NODE_PTR |
Functions | |
void | construct (int n) |
Method to construct the initial search structure to contain 'sz' elements. | |
static void | insertNode (NODE_PTR node, int value) |
Helper method to populate tree with actual nodes. | |
void | insert (int s) |
Method to insert an integer element into the search structure. | |
int | search (int target, int(*cmp)(const int, const int)) |
Method to search for an integer element in the search structure. | |
Variables | |
static NODE_PTR | root = NULL |
Root of the binary search tree. |
Receive integers one by one (in sorted order) and create a binary tree which means the tree heavily leans to the right and ultimately forms a linked list.
void construct | ( | int | n | ) |
Method to construct the initial search structure to contain 'sz' elements.
No work done since binary tree is constructed on the fly via insert(char *) method invocations.
n | the total number of elements to be inserted. |
void insert | ( | int | s | ) |
Method to insert an integer element into the search structure.
In our case, we insert the elements into a non-balancing tree.
s | Value to be inserted. |
static void insertNode | ( | NODE_PTR | node, | |
int | value | |||
) | [static] |
Helper method to populate tree with actual nodes.
int search | ( | int | target, | |
int(*)(const int, const int) | cmp | |||
) |
Method to search for an integer element in the search structure.
target | the desired target | |
cmp | the comparison function between two string elements. |
Algorithm Development Kit 1.0