Search/binarySearch.c File Reference

Task to perform number of binary search operations over a binary tree. Load up a number of strings into a non-balancing binary tree and define the search task for locating desired elements from within the tree. 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
 Standard Binary tree data structure to use.
typedef nodeNODE_PTR
 Standard Binary tree data structure to use.

Functions

void construct (int n)
 Method to construct the initial search structure to contain 'sz' elements.
static void insertNode (NODE_PTR node, char *value)
 Helper method to populate tree with actual nodes.
void insert (char *s)
 Method to insert an integer element into the search structure.
int search (char *target, int(*cmp)(const void *, const void *))
 Search for the desired target within the search structure.

Variables

static NODE_PTR root = NULL
 Head of binary tree.


Detailed Description

Task to perform number of binary search operations over a binary tree. Load up a number of strings into a non-balancing binary tree and define the search task for locating desired elements from within the tree.

Author:
George Heineman
Date:
6/15/08

Typedef Documentation

linkedListMoveToFront NODE

Standard Binary tree data structure to use.

typedef struct node * NODE_PTR

Standard Binary tree data structure to use.


Function Documentation

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.

Parameters:
n the total number of elements to be inserted.

void insert ( char *  s  ) 

Method to insert an integer element into the search structure.

In our case, we insert the elements into a non-balancing tree.

Parameters:
s Value to be inserted.

static void insertNode ( NODE_PTR  node,
char *  value 
) [static]

Helper method to populate tree with actual nodes.

int search ( char *  target,
int(*)(const void *, const void *)  cmp 
)

Search for the desired target within the search structure.

Parameters:
target the desired target
cmp the comparison function between two string elements.


Variable Documentation

NODE_PTR root = NULL [static]

Head of binary tree.

Algorithm Development Kit 1.0