Exemple #1
0
void test_insert(){
	RBTree<char,int> rb;
	cout << "*************************************************" << endl;
	rb.insert('S', 0);
	//printBST(rb);	
	rb.insert('E', 0);
	//printBST(rb);
	rb.insert('A', 0);
	//printBST(rb);
	rb.insert('R', 0);
	//printBST(rb);
	rb.insert('C', 0);
	//printBST(rb);
	rb.insert('H', 0);
	//printBST(rb);
	rb.insert('X', 0);
	//printBST(rb);
	rb.insert('M', 0);
	//printBST(rb);
	rb.insert('P', 0);
	//printBST(rb);
	rb.insert('L', 0);
	printBST(rb);
	cout << "************************************************" << endl;
	cout << "min is " << rb.min()<<endl;
//	while( !rb.empty() ){
//		rb.removeMax();
//		cout << rb ;
//	}
	cout << "=====================================" <<endl;
	
	rb.remove('A');

	cout << rb;

	cout << endl;

}
Exemple #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;
}