Beispiel #1
0
void delete_rbt(){
	RBTree<unsigned, double> rb;
	double v;
	srand(time(NULL));
	for(unsigned i=0; i<1e4; ++i){
		v = rand() * 1001 * 0.001f;
		rb.insert(i,v);
	}
	cout<< "height is " << rb.height() << endl;
	cout<< "# of left rotation = " << NUM_OF_LEFT_ROTATION << endl;
	cout<< "# of right rotation = " << NUM_OF_RIGHT_ROTATION <<endl;
	unsigned n;
	while( cin >> n ){
		cout <<"key = " << n << "\tvalue = " <<  rb.get(n) << endl;
		if (n==1) break;
	}
	cout <<"size of BST is " << rb.size() << endl;

	cout <<"=====================ceiling floor======================" << endl;
	cout <<"floor of 4 is " << rb.floor(4) << endl;
	cout <<"floor of 9 is " << rb.floor(9) << endl;
	cout <<"ceiling of 4 is " << rb.ceiling(4) << endl;
	cout <<"ceiling of 9 is " << rb.ceiling(9) << endl;
	cout <<" is 2-3 tree ?  " << rb.isLeftLeaning23tree() << endl;
	cout <<"is size consistent ?  " << rb.isSizeConsistent() << endl;
	cout <<"Is balanced search tree ?  " << rb.isBalancedSearchTree() << endl;
	cout <<"is rank consistent ?  " << rb.isRankConsistent() << endl;

}
Beispiel #2
0
void test_rbt(){
	RBTree<int, string> rb;
	create_rbt(rb);
	cout << rb;
	cout << "is empty? " << rb.empty()<<endl;
	cout << "height of rb is ? " << rb.height() <<endl;
	cout << "min key = " << rb.min() << endl;
	cout << "max key = " << rb.max() << endl;
	cout << "max key rank of 30 is " << rb.rank(30) << endl;
	cout << "4th key is " << rb.select(4) << endl;
	cout << "keys are: " << endl;
//	deque<int> keys = rb.keys(); 
//	for( deque<int>::iterator it = keys.begin(); it != keys.end(); ++it){
//		cout << *it << " ";
//	}
	
	rb.removeMin();

	cout << rb ;
	cout << "=====================================" <<endl;
	
	cout << endl;
}
Beispiel #3
0
void printBST(RBTree<char,int> &rb){
	cout << rb;
	cout << "height of tree is: " << rb.height() << endl;
}