/**************************************************************************
 * Source Id :
 *
 * $Id: dbbst.h,v 1.1 2001/04/03 20:10:26 aleksandras Exp $
 *-------------------------------------------------------------------------
 * Project Notes :
 *
 *  Diamond Base
 *  ============
 *      A solid database implementation, spurred on by the continuing
 *  Metal (Lead) Base saga.
 *
 *  Project Team :
 *        A. Davison
 *        K. Lentin
 *        D. Platt
 *
 *	Project Commenced : 05-02-1993
 *
 *-------------------------------------------------------------------------
 *  Module Notes :
 *
 *		A simple BST implementation
 *
 *  Original Author :
 *		Andy
 *
 **************************************************************************/

#ifndef __DB_BST_H__
#define __DB_BST_H__

#include <iostream.h>
#include <diamond/defs.h>

struct DBBSTNode
{
	DBBSTNode*	_left;
	DBBSTNode*	_right;

		DBBSTNode(void) {_left = _right = 0;}

	virtual int compare(const DBBSTNode*, const DBBSTNode*) = 0;
	virtual void show() = 0;

	bool		insert(DBBSTNode * const node);
	DBBSTNode*	lookup(const DBBSTNode * node);

	void inorder();

};

class DBBST
{
	DBBSTNode*	tree;

public:
		DBBST() {tree = 0;}

		bool insert(DBBSTNode * const node)
		{
			bool res;
			if (tree == 0)
			{
				tree = node;
				res = true;
			}
			else
			{
				res = tree->insert(node); 
			}
			return res;
		}
		DBBSTNode* lookup(const DBBSTNode* node)
		{
			return tree?tree->lookup(node):0;
		}

		void inorder()
		{
			if (tree != 0)
				tree->inorder();
		}
};

#endif

//////////////////////////////////////////////////////////////////////////
// $Log: dbbst.h,v $
// Revision 1.1  2001/04/03 20:10:26  aleksandras
// big one 3.1 (comments later)
//
// Revision 1.8  1995/06/27  13:27:16  kevinl
// Fixes to repair the gcc 2.7.0 carnage:
// modified for loop local variable scope semantics
// some new errors invented.
// moved some inline friends out of classes (stoopid - mystring)
// Modified the setUnique generated member
//
// Revision 1.7  1995/02/03  01:03:36  kevinl
// Added a diamond/
//
// Revision 1.6  1994/12/13  06:52:12  kevinl
// No includes defs
//
// Revision 1.5  1994/12/12  03:54:14  kevinl
// Fixed problems with return code of tree insertion
//
// Revision 1.4  1994/05/15  05:01:32  kevinl
// Changing char* to dbString
//
// Revision 1.3  1994/02/03  05:50:31  kevinl
// Moved include files to diamond/ and fixed HAVE_MALLOC_H
//
// Revision 1.2  1994/01/24  05:05:04  kevinl
// Added a log
//
//////////////////////////////////////////////////////////////////////////
