当前位置: 首页>>代码示例>>C++>>正文


C++ BST::Insert方法代码示例

本文整理汇总了C++中BST::Insert方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::Insert方法的具体用法?C++ BST::Insert怎么用?C++ BST::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BST的用法示例。


在下文中一共展示了BST::Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
	BST<int> t;
	
	int a[8] = {30,10,16,35,40,5,33,11};

	for(int i=0; i < 8; i++)
	{
		t.Insert(a[i]);
	}
	t.DisplayInorder();
	cout << endl;

	BST<string> q;
	string days[7] = {"Mon", "Tue", "Wed", "Thr", "Fri", "Sat", "Sun"};


	for(int i=0; i < 7; i++)
	{
		q.Insert(days[i]);
	}

	q.DisplayInorder();
	cout << endl;

	BST<char> r;
	for(char i='A'; i <='K'; i++)
	{
		r.Insert(i);
	}
	r.DisplayInorder();
	cout << endl;
	system("pause");
	return 0;
}
开发者ID:kevin-miles,项目名称:cmps-385-data-structures,代码行数:35,代码来源:example.cpp

示例2: main

int main()
{
	BST bst;
	
	if(bst.Empty())
		cout << "BST::Empty() works" << endl;
	else
		cout << "BST::Empty() doesn't work" << endl;
		
	bst.Insert(0);
	
	if(!bst.Empty())
		cout << "BST::Empty() works" << endl;
	else
		cout << "BST::Empty() doesn't work" << endl;
		
	if(bst.Delete(0))
		cout << "BST::Delete(const int) works" << endl;
	else
		cout << "BST::Delete(const int) doesn't work" << endl;
		
	if(!bst.Delete(-1))
		cout << "BST::Delete(const int) works" << endl;
	else
		cout << "BST::Delete(const int) doesn't work" << endl;
	
	for(int i = 0; i < 10; i++)
		bst.Insert(i);
		
	cout << bst.Min() << endl;
	cout << bst.Max() << endl;
	
	if(bst.SearchIter(0) && !bst.SearchIter(10))
		cout << "BST::SearchIter(const int) works" << endl;
	else
		cout << "BST::SearchIter(const int) doesn't work" << endl;
		
	if(bst.SearchRec(0) && !bst.SearchRec(10))
		cout << "BST::SearchRec(const int) works" << endl;
	else
		cout << "BST::SearchRec(const int) doesn't work" << endl;
		
	bst.Clear();
	
	if(bst.Empty())
		cout << "BST::Empty() works" << endl;
	else
		cout << "BST::Empty() doesn't work" << endl;

	return 0;

} // end main()
开发者ID:deanmarc25,项目名称:bst,代码行数:52,代码来源:bst_test.cpp

示例3: populateTree

//Fills a tree with criminals from a text file
void populateTree(BST& tree, string file)
{
	string currentLine = "";
	ifstream criminals(file);
	getline(criminals, currentLine);											//Gets first SUBJECT line
	
	while (!criminals.eof())
	{
		string data = "";
		getline(criminals, currentLine);										//Gets name of criminal

		if (currentLine != "FINISHED")
		{
			while (currentLine != "SUSPECT")
			{
				data += currentLine + " ";
				getline(criminals, currentLine);								//Gets attributes and subsequent SUBJECTs
			}

			Criminal insertion = Criminal(data);
			tree.Insert(insertion);
		}
		else
		{
			criminals.close();
			return;
		}
	}
}
开发者ID:weather3003,项目名称:BST-Application,代码行数:30,代码来源:criminal.cpp

示例4: main

int main()
{
    BST *btree = new BST;
    btree->Insert("kiwi");
    btree->Insert("mango");
    btree->Insert("apple");
    // display in preorder form
    btree->preOrder();
    cout << endl;
    btree->inOrder();
    cout << endl;
    btree->postOrder();
    cout << endl;



    return 0;
}
开发者ID:ZenithIO89,项目名称:myfantastic-stuff,代码行数:18,代码来源:main.cpp

示例5: openAccount

void openAccount(BST<int> B)
{
	int id, balance;
	string name;
	cout << "\tEnter the name: ";
	cin >> name;
	cout << "\tEnter the balance: ";
	cin >> balance;
	cout << "\tEnter the new ID: ";
	cin >> id;
	B.Insert(id, name, balance);
}
开发者ID:kevin-miles,项目名称:cmps-385-data-structures,代码行数:12,代码来源:1v2.cpp

示例6: main

int main(int argc,char **argv)
{
  // Create an empty Binary Search Tree
  BST Tree;
  string input = "";
  while (input !="ENDINSERT")
  {
     cin >> input;
     if (input != "ENDINSERT")
     	Tree.Insert(input);     
  }
  Tree.Print("POST");
}
开发者ID:Sudoka,项目名称:C_Plus_Plus_Examples,代码行数:13,代码来源:BSTinserting.cpp

示例7: main

int main(int argc,char **argv)
{
    // Create an empty Binary Search Tree
    BST Tree;
    string input;
    cin >> input;
    while(input != "ENDINSERT") {
        //cout << "got here" << endl;
        Tree.Insert(input);
        cin >> input;
    }
    //cout << "done inserting" << endl;
    Tree.Print("POST");
}
开发者ID:Sudoka,项目名称:algorithms,代码行数:14,代码来源:BSTinserting.cpp

示例8: main

void main() // key(pair사용시 data.first) = 노드의 이름 같은 개념,  element(pair 사용시 data.second)  = 노드의 고유 data
{
	//declare the type of K, E
	typedef  int K;
	typedef char E;
	BST<K, E> HWbst;	// Making BST class HWbst  link every nodes

	int menu = 0;
	while (1)
	{
		//   Menu   //
		cout << endl << " #### Choose Menu ####" << endl;
		cout << "1. Insert      2. Delete      3. Print      4. Exit" << endl;
		cin >> menu;
		switch (menu)
		{
			case 1: // Insert Menu
			{
					  
					  pair<K, E> A;  // new node's pair type data
					  cout << " *** 새로운 TreeNode의 Key : ";
					  cin >> A.first;
					  cout << " *** 새로운 TreeNode의 Element : ";
					  cin >> A.second;

					  HWbst.Insert(A); // use insert function
					  break;
					  
			}
			case 2: // Delete Menu
			{	
					  int a = 0;
					  cout << " *** 삭제할 노드의 Key 입력  :  ";
					  cin >> a;
					  HWbst.Delete(a);
					  break;
			}
			case 3: // Print all nodes by level order
			{
					  HWbst.Print();
					  break;
			}
			case 4:  // close this program
			{
					  return;
			}
		}
	}
	
}
开发者ID:jaeen1113,项目名称:HW_Project,代码行数:50,代码来源:main.cpp

示例9: main

int main()
{
	char restart;
    char selection;
	BST<string> p;
	string sentence = "George Samsa awoke one morning only to discover "
					   "he had been transformed into a giant Cockroach";

    istringstream iss(sentence);
    while(iss)
    {
    	string word;
    	iss >> word;
    	p.Insert(strtolower(word));
    }
    do{
    cout << "a.\tDisplay the words in alphabetical order\n"
    	 << "b.\tdisplay the tree sideways\n"
    	 << "c.\tHow many leaves does the tree have\n"
    	 << "d.\tWhat is the height of the tree\n"
    	 << "e.\tSelect a random letter from a-z and delete all words that begin with that letter\n\n";

    cout << "Make a selection: ";
    cin >> selection;
    switch(tolower(selection))
    {
    case 'a':
    	cout << "\nWords in alphabetical order: ";
    	p.DispTree();
    	cout << endl;
    	break;
    case 'b':
    	p.DispSideway();
    	break;
    case 'c':
    	cout << "\nNumber of leaves in tree: ";
    	p.countNodes();
    	break;
    case 'd':
    	cout << "\nHeight of tree: ";
    	p.treeHeight();
    	break;
    }
    cout << "\nAgain(Y/N)?: ";
    cin >> restart;
    cout << endl;
    }while(toupper(restart) == 'Y');

	return 0;
}
开发者ID:danjordan2,项目名称:CPSC301,代码行数:50,代码来源:301Project9-1.cpp

示例10: main

int main(int argc,char **argv)
{
  // Create an empty Binary Search Tree
  BST Tree;
  //Tree=new BST();
  string input;
  cin>>input;
  while(input!="ENDINSERT"){
	Tree.Insert(input);
	
	cin>>input;
  }
  Tree.Print("POST");
}
开发者ID:vjain05,项目名称:CSE100labs,代码行数:14,代码来源:BSTinserting.cpp

示例11: main

int main(int argc, char** argv)
{
	atexit(ExitHook);

	BST<int> bst;
	Dumper<int> dumper;
	std::vector<int> vec;

	vec.reserve(NT);

	for (int i = 0; i < N; ++i)
		vec.push_back(i);

	std::random_shuffle(vec.begin(), vec.end());
#if DUMP
	std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
	std::endl(std::cout);
#endif

	for (int i = 0; i < (int)vec.size(); ++i)
		bst.Insert(vec[i]);

#if DUMP
	bst.Accept(dumper);
	std::endl(std::cout);
#endif

	for (int i = 0; i < NT; ++i)
	{
		bool ret = bst.Remove(i);
#if DUMP
		std::cout << "Remove " << i << " " << ret << std::endl;
#endif
	}

#if DUMP
	bst.Accept(dumper);
	std::endl(std::cout);
#endif

	return 0;
}
开发者ID:KibaAmor,项目名称:notes,代码行数:42,代码来源:bsttest.cpp

示例12: main

int main(int argc , char* argv[])
{
	BST<TermRec> T;
	ifstream F("flist.txt") , file ;
	ofstream fp(argv[1]);
	
	if (!F.is_open()) {
		cout << "\nError opening file flist.txt , Aborting!!";
		return -1;}
	string file_to_be_indexed , line , word , file_name;
	int line_no , i , start;
	TermRec *Node , *word_obj;
	
	while (getline( F , file_to_be_indexed )) {
		file.open(file_to_be_indexed.c_str());
		if (file.is_open()) {
			start = 0;
			while ( (i = file_to_be_indexed.find("/",start)) != std::string::npos )		//finding file name
				start = i+1;
			file_name = file_to_be_indexed.substr(start);
			line_no = 1;
			while (getline(file , line)) {
				start = 0;
				line.append(" ");
				while ( (i = line.find(" ",start)) != std::string::npos) {
					word = line.substr(start , i-start);
					for ( int j=0 ; j < word.length() ; j++) 
						word[j] = tolower(word[j]);
					word_obj = new TermRec( word );
					Node = T.Insert(word_obj);
					Node->Insert(file_name , line_no);
					delete word_obj;
					start = i+1;
					while (line[start] == ' ')		//to accomodate more than one space between words
						start++;} 
				line_no++;} 	
				file.close();}
		else 
			cout << "\nError opening file " << file_to_be_indexed; }
	write_to_file(T.get_root() , fp);
	return 0;
}
开发者ID:ibrahim5253,项目名称:random_codes,代码行数:42,代码来源:File_indexing.cpp

示例13: main

int main() {
	BST<int> tree;
	int a[6] = {25, 9, 36, 2, 17, 40};
	for (int i = 0; i < 6; i++) {
		tree.Insert(a[i]);
	}

	cout << "\nInorder Traversal Display: \n";
	tree.DisplayInorder();
	cout << "\n\nPostorder Traversal Display: \n";
	tree.DisplayPostorder();
	cout << "\n\nPreorder Traversal Display: \n";
	tree.DisplayPreorder();
	cout << "\n\nDisplay Leaves only: \n";
	tree.DisplayLeaves();
	cout << "\n\nDisplay Parents only: \n";
	tree.DisplayParent();
 	cout << endl << endl;
	return 0;
}
开发者ID:blenderben,项目名称:CMPS385,代码行数:20,代码来源:Project10-2_BST.cpp

示例14: main

int main(int argc,char **argv)
{
  // Create an empty Binary Search Tree
  BST Tree;
  string input;
  cin>>input;
  while(input!="ENDINSERT"){
	Tree.Insert(input);
	
	cin>>input;
  }
  //Tree.Print("POST");
  //cout<<"transition"<<endl;
  cin>>input;
  while(input!="ENDDELETE"){
		Tree.Delete(input);
	  cin>>input;
  }
  Tree.Print("POST");
}
开发者ID:vjain05,项目名称:CSE100labs,代码行数:20,代码来源:BSTdeleting.cpp

示例15: main

int main(){
    LinkedList tList = LinkedList();

	char* c = new char[3];
	c[1] = '\n';
	c[2] = '\0';

    for(int i = 0; i < 200000; i++){
    	c[0] = (char)i;
    	tList.Insert(c, NULL);
    }

	tList = tList;
	cout << "LinkedList contents:" << tList.GetSize() << endl;
    //tList->Output(cout);

    //tList->Clear();
    LinkedList tNew = tList;
    //tList->Clear();

    cout << endl << endl << "List Copy contents:" << tNew.GetSize() << endl;
	//tNew.Output(cout);

    BST* tBST = new BST();
    BSTNode* tBSTNode;

    tBSTNode = tBST->Insert("Cool\n");
    tBSTNode = tBST->Insert("Awesome\n");
    tBSTNode = tBST->Insert("Test\n");
    tBSTNode = tBST->Insert("1\n");
    //tBST->Remove(tBSTNode);
    tBSTNode = tBST->Insert("4\n");
    tBSTNode = tBST->Insert("2\n");
    tBSTNode = tBST->Insert("3\n");

    cout << endl << endl << "BST contents:" << tBST->GetSize() << endl;
    tBST->Output(cout, tBST->GetRoot());


    delete tBST;
}
开发者ID:B0bTh3BuiIder,项目名称:cs240,代码行数:41,代码来源:main.cpp


注:本文中的BST::Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。