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


C++ Tree::Delete方法代码示例

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


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

示例1: main

int main(){
	Tree mTree;
	mTree.setHead();
	mTree.CreateTree(mTree.head,32);			//expected height of the tree	is 33.
	int Q; 
	string s;
	int num;
	for(int i=0;i<Q;i++){
		cin>>s;
		cin>>num;
		switch (s[0]){
		case 'a':		//add
			mTree.Insert(num);			
			break;
		case 'd':		//delete
			mTree.Delete(num);
			break;
		case 'c':		//count
			mTree.TotalCount=0;
			mTree.GetCount(mTree.head,num);
			cout<<mTree.TotalCount<<endl;			
			break;
		}
	}


	return 0;
}
开发者ID:AbhishekTiwari0812,项目名称:hackerrank_problems,代码行数:28,代码来源:counter_code6.cpp

示例2: main

void main()
{
	Tree t;
	int ch=0,x;
	while(ch!=6)
	{
		cout<<"\n\n----Tree----\n";
		cout<<"\n1.Inorder";
		cout<<"\n2.Preorder";
		cout<<"\n3.Postorder";
		cout<<"\n4.Insert";
		cout<<"\n5.Delete";
		cout<<"\n6.Exit";
		cout<<"\nEnter the choice :";
		cin>>ch;
		switch(ch)
		{
		case 1:
			cout<<"\nInorder  : ";
			t.Inorder();
			break;

		case 2:
			cout<<"\nPreorder :";
			t.Preorder();
			break;
		case 3:
			cout<<"\nPostorder:";
			t.Postorder();
			break;
		case 4:
			cout<<"\nEnter the data:";
			cin>>x;
			t.Insert(x);
			break;
		case 5:
			cout<<"\nEnter the data:";
			cin>>x;
			t.Delete(x);
			break;
		}
	}
	
	

}
开发者ID:prijuly2000,项目名称:Data-Structure,代码行数:46,代码来源:main.cpp

示例3: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	Tree<int>* tr = new Tree<int>();
	tr->Add(123, "abcdef");
	tr->Add(456, "abde");
	tr->Add(789, "aaaa");
	tr->Add(145, "a");
	tr->Add(464, "ab");
	tr->Print("Tree");
	cout << endl;
	tr->Add(444, "a");
	cout << endl;
	tr->Find("abde");
	cout << endl;
	tr->Delete("abde");
	tr->Print("After deleting record (key - abde)");
	getchar();
	return 0;
}
开发者ID:juravlikk,项目名称:Tree,代码行数:19,代码来源:Tree.cpp

示例4: menu

void  menu()
{
	Tree *tree = new Tree;
	char c;
	do
	{
		printf("1: View\n");
		printf("2: Find\n");
		printf("3: Add\n");
		printf("4: Del\n");
		printf("5: Clear\n");
		printf("\nEsc: Exit\n");
		c = getch();
		switch(c)
		{
		case '1': 
			cout << "Print:";
			tree->Print();
			cout << endl; break;
		case '2': 
			cout << "Find:";
			int val;
			cin >> val;
			bool flag;
			flag = tree->Exists(val); 
			cout << (flag == true ? "true" : "false") << endl; break;
		case '3': 
			cout << "Add:";
			int add;
			cin >> add;
			tree->Add(add); cout << endl; break;
		case '4': 
			cout << "Delete:";
			int del;
			cin >> del;
			tree->Delete(del); cout << endl; break;
		case '5': tree->Clear();  cout << endl; break;
		}
	} while(c != 27);
	delete tree;
}
开发者ID:klyuchnikov,项目名称:LabsThreeSemestrsEVM,代码行数:41,代码来源:Main.cpp

示例5: main

int main(){
	Tree t;

	(t.Root) = new node;
	t.Root->value=8;
	t.Root->parent = t.Root;

	//Initialize Full Tree
	t.Add(8);
	t.New(4,*((t.Root)),0);
	t.New(2,(*(t.Root)->L),0);
	t.New(6,(*(t.Root)->L),1);
	t.New(12,*((t.Root)),1);
	t.New(10,(*(t.Root)->R),0);
	t.New(14,(*(t.Root)->R),1);
	t.New(1,(*(t.Root)->L->L),0);
	t.New(3,(*(t.Root)->L->L),1);
	t.New(5,(*(t.Root)->L->R),0);
	t.New(7,(*(t.Root)->L->R),1);
	t.New(9,(*(t.Root)->R->L),0);
	t.New(11,(*(t.Root)->R->L),1);
	t.New(13,(*(t.Root)->R->R),0);
	t.New(15,(*(t.Root)->R->R),1);
	cout<<"\n# Original Tree :"<< endl;
	t.DisplayTree();
	avg_num=0;
	avg_total=0;

	//Search Operations
	for (int i=15;i>0;i--){
		t.Search(i);
	}
	int avg_total1 = avg_total;
	int avg_num1 = avg_num;
	avg_total=0;
	avg_num=0;

	//Delete Operations
	t.Delete(15);
	t.Delete(14);
	t.Delete(4);
	t.Delete(5);
	t.Delete(1);

	cout<<"\nAverage Rotations for Search Operation:"<<(float)avg_total1/avg_num1;
	cout<<"\nAverage Rotations for Delete Operation:"<<(float)avg_total/avg_num;
//	int a;
//	cout<< "Root :";
//	t.DisplayNode( *(t.Root));
//	node* m =(t.Root);
//	while(1){
//		cout<<endl<<"Enter Selection :";
//		cin>>a;
//		if(a==1){
//			cout<<"Add :";
//			cin>>a;
//			t.Add(a);
//			m =(t.Root);
//		}
//		else if(a==2){//Delete
//			cout<<"Delete :";
//			cin>>a;
//			t.Delete(a);
//			m =(t.Root);
//		}
//		else if(a==3){//Current
//			t.DisplayNode(*m);
//		}
//		else if(a==4){//Root
//			cout<<"Root :";
//			t.DisplayNode( *(t.Root));
//		}
//		else if(a==5){//Left
//			m=(*m).L;
//			t.DisplayNode( *(m));
//		}
//		else if(a==6){//Right
//			m=(*m).R;
//			t.DisplayNode( *(m));
//		}
//		else if(a==7){//Up
//			m=(*m).parent;
//			t.DisplayNode( *(m));
//		}
//
//
//	}

}
开发者ID:sumeetfefar,项目名称:advanced-computing-assignments,代码行数:89,代码来源:q3.cpp


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