/*
 * Faculty of Applied Science and Engineering, University of Toronto
 * CSC181: Introduction to Computer Programming, Fall 2000
 *
 * Assignment: 3
 * File: bst.c
 * Author: Ray Ortigas (rayo@dgp.toronto.edu)
 * Contains: Function definitions for BST module.
 */

#include <assert.h>
#include <stdlib.h>
#include "bst.h"

/* Returns a binary search tree which uses compareKeys (a pointer to
   function taking two void* arguments) to carry out comparisons
   between two keys. */
BSTPtr bstInit(int (*compareKeys)(void*, void*)) {
	BSTPtr result = malloc(sizeof(BST));
	assert(result != NULL);

	result->root = NULL;
	result->compareKeys = compareKeys;

	return result;
}

/* Inserts key k and associated value v into tree t. */
void bstInsert(BSTPtr t, void* k, void* v) {

	/* FIXME
	 *
	 * Note: To compare two keys, you will need to call the function
	 * 't->compareKeys' using the following syntax:
	 *
	 * (*(t->compareKeys))(k1, k2)
	 *
	 * The function returns an int, so you can use that to decide
	 * where in the tree the key and value belong.
	 */
}

/* Retrieves the value associated with key k inside tree t, NULL if no
   such value exists. */
void* bstRetrieve(const BSTPtr t, void* k) {
	void* result;

	/* FIXME
	 *
	 * Note: Just before this function returns, 'result' should contain
	 * the value to be returned by this function, as described in the
	 * function comment above.
	 */
	
	return result;
}
