All pastes #182772 Raw Edit

Something

public text v1 · immutable
#182772 ·published 2006-09-26 10:33 UTC
rendered paste body
#include "BinarySearchTree.h"
#include <cstdlib>
using namespace std;

BinarySearchTree::BinarySearchTree()
{
	left = NULL;
	right = NULL;
	key = -1;
	depth = -1;
	pos = -1;
}

BinarySearchTree::BinarySearchTree(int k)
{
	left = NULL;
	right = NULL;
	key = k;
	depth = 0;
	pos = 0;
}

void BinarySearchTree::insert(int k, tree &t, int depth)
{
	if( t == NULL )
	{
		t = new tree(k);
		t.setDepth(depth);
		t.left = NULL;
		t.right = NULL;
	}
	else if( k < t.getKey() )
	{
		insert(k, t.left, t.getDepth()+1);
	}
	else if( k > t.getKey() )
	{
		insert(k, t.right, t.getDepth()+1);
	}
	else
	{
		cerr << "Duplicate key" << endl;
	}

}

int BinarySearchTree::getKey()
{
	return key;
}

int BinarySearchTree::getPos()
{
	return pos;
}

int BinarySearchTree::getDepth()
{
	return depth;
}

void BinarySearchTree::setPos(int p)
{
	pos = p;
}

void BinarySearchTree:setDepth(int d)
{
	depth = d;
}