⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.h

📁 二叉树建立
💻 H
📖 第 1 页 / 共 3 页
字号:
			this->源码查看ToolStripMenuItem->Name = L"源码查看ToolStripMenuItem";
			this->源码查看ToolStripMenuItem->Size = System::Drawing::Size(79, 20);
			this->源码查看ToolStripMenuItem->Text = L"源码查看";
			// 
			// 图广度优先ToolStripMenuItem
			// 
			this->图广度优先ToolStripMenuItem->Name = L"图广度优先ToolStripMenuItem";
			this->图广度优先ToolStripMenuItem->Size = System::Drawing::Size(149, 22);
			this->图广度优先ToolStripMenuItem->Text = L"图广度优先";
			this->图广度优先ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::图广度优先ToolStripMenuItem_Click);
			// 
			// 关闭源码ToolStripMenuItem
			// 
			this->关闭源码ToolStripMenuItem->Name = L"关闭源码ToolStripMenuItem";
			this->关闭源码ToolStripMenuItem->Size = System::Drawing::Size(149, 22);
			this->关闭源码ToolStripMenuItem->Text = L"关闭源码";
			this->关闭源码ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::关闭源码ToolStripMenuItem_Click);
			// 
			// 图深度优先ToolStripMenuItem
			// 
			this->图深度优先ToolStripMenuItem->Name = L"图深度优先ToolStripMenuItem";
			this->图深度优先ToolStripMenuItem->Size = System::Drawing::Size(149, 22);
			this->图深度优先ToolStripMenuItem->Text = L"图深度优先";
			this->图深度优先ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::图深度优先ToolStripMenuItem_Click);
			// 
			// 退出ToolStripMenuItem
			// 
			this->退出ToolStripMenuItem->Name = L"退出ToolStripMenuItem";
			this->退出ToolStripMenuItem->Size = System::Drawing::Size(49, 20);
			this->退出ToolStripMenuItem->Text = L"退出";
			this->退出ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::退出ToolStripMenuItem_Click);
			// 
			// pictureBox1
			// 
			this->pictureBox1->Location = System::Drawing::Point(87, 150);
			this->pictureBox1->Margin = System::Windows::Forms::Padding(4);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(391, 146);
			this->pictureBox1->TabIndex = 1;
			this->pictureBox1->TabStop = false;
			this->pictureBox1->DoubleClick += gcnew System::EventHandler(this, &Form1::pictureBox1_DoubleClick);
			// 
			// groupBoxTree
			// 
			this->groupBoxTree->Controls->Add(this->button2);
			this->groupBoxTree->Controls->Add(this->buttonCreatTree);
			this->groupBoxTree->Controls->Add(this->textBoxBiTree);
			this->groupBoxTree->Location = System::Drawing::Point(16, 5375);
			this->groupBoxTree->Margin = System::Windows::Forms::Padding(4);
			this->groupBoxTree->Name = L"groupBoxTree";
			this->groupBoxTree->Padding = System::Windows::Forms::Padding(4);
			this->groupBoxTree->Size = System::Drawing::Size(637, 108);
			this->groupBoxTree->TabIndex = 3;
			this->groupBoxTree->TabStop = false;
			this->groupBoxTree->Text = L"以广义表形式输入一颗二叉树";
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(535, 64);
			this->button2->Margin = System::Windows::Forms::Padding(4);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(100, 29);
			this->button2->TabIndex = 5;
			this->button2->Text = L"关闭";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// buttonCreatTree
			// 
			this->buttonCreatTree->Location = System::Drawing::Point(535, 26);
			this->buttonCreatTree->Margin = System::Windows::Forms::Padding(4);
			this->buttonCreatTree->Name = L"buttonCreatTree";
			this->buttonCreatTree->Size = System::Drawing::Size(100, 29);
			this->buttonCreatTree->TabIndex = 4;
			this->buttonCreatTree->Text = L"建立";
			this->buttonCreatTree->UseVisualStyleBackColor = true;
			this->buttonCreatTree->Click += gcnew System::EventHandler(this, &Form1::buttonCreatTree_Click);
			// 
			// textBoxBiTree
			// 
			this->textBoxBiTree->Location = System::Drawing::Point(27, 25);
			this->textBoxBiTree->Margin = System::Windows::Forms::Padding(4);
			this->textBoxBiTree->Multiline = true;
			this->textBoxBiTree->Name = L"textBoxBiTree";
			this->textBoxBiTree->Size = System::Drawing::Size(499, 66);
			this->textBoxBiTree->TabIndex = 3;
			// 
			// groupBoxGraph
			// 
			this->groupBoxGraph->Controls->Add(this->buttonGraphCreate);
			this->groupBoxGraph->Controls->Add(this->textBoxGraph);
			this->groupBoxGraph->Location = System::Drawing::Point(113, 4600);
			this->groupBoxGraph->Margin = System::Windows::Forms::Padding(4);
			this->groupBoxGraph->Name = L"groupBoxGraph";
			this->groupBoxGraph->Padding = System::Windows::Forms::Padding(4);
			this->groupBoxGraph->Size = System::Drawing::Size(559, 308);
			this->groupBoxGraph->TabIndex = 5;
			this->groupBoxGraph->TabStop = false;
			this->groupBoxGraph->Text = L"输入图的信息,第一排为节点,第二排起为边";
			// 
			// buttonGraphCreate
			// 
			this->buttonGraphCreate->Location = System::Drawing::Point(487, 39);
			this->buttonGraphCreate->Name = L"buttonGraphCreate";
			this->buttonGraphCreate->Size = System::Drawing::Size(59, 19);
			this->buttonGraphCreate->TabIndex = 6;
			this->buttonGraphCreate->Text = L"确定";
			this->buttonGraphCreate->UseVisualStyleBackColor = true;
			this->buttonGraphCreate->Click += gcnew System::EventHandler(this, &Form1::buttonGraphCreate_Click);
			// 
			// textBoxGraph
			// 
			this->textBoxGraph->Location = System::Drawing::Point(17, 26);
			this->textBoxGraph->Margin = System::Windows::Forms::Padding(4);
			this->textBoxGraph->Multiline = true;
			this->textBoxGraph->Name = L"textBoxGraph";
			this->textBoxGraph->ScrollBars = System::Windows::Forms::ScrollBars::Both;
			this->textBoxGraph->Size = System::Drawing::Size(463, 259);
			this->textBoxGraph->TabIndex = 5;
			this->textBoxGraph->Text = L"A B C D E F G H I J K\r\n0 2\r\n0 3\r\n0 5\r\n0 8\r\n0 10\r\n1 2\r\n1 4\r\n1 7\r\n1 9\r\n2 3\r\n2 6\r\n2 " 
				L"9\r\n2 10\r\n3 5\r\n3 8\r\n4 10\r\n5 7\r\n5 9\r\n5 10\r\n6 8\r\n6 10\r\n7 9\r\n8 10\r\n9 10";
			// 
			// richTextBoxBFS
			// 
			this->richTextBoxBFS->Font = (gcnew System::Drawing::Font(L"Arial", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->richTextBoxBFS->Location = System::Drawing::Point(43, 4700);
			this->richTextBoxBFS->Name = L"richTextBoxBFS";
			this->richTextBoxBFS->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::ForcedBoth;
			this->richTextBoxBFS->Size = System::Drawing::Size(995, 800);
			this->richTextBoxBFS->TabIndex = 6;
			this->richTextBoxBFS->Text = resources->GetString(L"richTextBoxBFS.Text");
			// 
			// richTextBoxDFS
			// 
			this->richTextBoxDFS->Font = (gcnew System::Drawing::Font(L"Arial", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->richTextBoxDFS->Location = System::Drawing::Point(5200, 36);
			this->richTextBoxDFS->Name = L"richTextBoxDFS";
			this->richTextBoxDFS->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::ForcedBoth;
			this->richTextBoxDFS->Size = System::Drawing::Size(995, 800);
			this->richTextBoxDFS->TabIndex = 7;
			this->richTextBoxDFS->Text = resources->GetString(L"richTextBoxDFS.Text");
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(8, 15);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1099, 578);
			this->Controls->Add(this->richTextBoxDFS);
			this->Controls->Add(this->richTextBoxBFS);
			this->Controls->Add(this->groupBoxGraph);
			this->Controls->Add(this->groupBoxTree);
			this->Controls->Add(this->pictureBox1);
			this->Controls->Add(this->menuStrip1);
			this->MainMenuStrip = this->menuStrip1;
			this->Margin = System::Windows::Forms::Padding(4);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			this->groupBoxTree->ResumeLayout(false);
			this->groupBoxTree->PerformLayout();
			this->groupBoxGraph->ResumeLayout(false);
			this->groupBoxGraph->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void 二叉树建立ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
				this->groupBoxTree->Top=50;
				this->groupBoxTree->Left=50;
				 
			 }
	
			 private:  DSchen::BiTree *CreateBitree(String ^ s){
						   int n=s->Length,i,top=-1,LR;
						   BiTree *stack[20];
						   BiTree *tmp,*pr;
						  // this->textBoxBiTree->Text=s[0].ToString();
						   for(i=0;i<n;++i){
							   switch(s[i]){
								   case '(':
									   stack[++top]=tmp; //刚刚建立的节点为正在处理的根
									   LR=0;
									   pr=tmp;
									   break;
								   case ')':
									   top--;
									   if(top==-1)return root;
									   else pr=stack[top];
									   break;
								   case ',':
									   LR=1;
									   break;
								   default:
									   tmp=new BiTree();
									   tmp->data=s[i];
									   if(i==0){root=tmp;pr=tmp;}
									   else{
										   if(LR==0)   pr->Lchild=tmp;
										   else        pr->Rchild=tmp;
										   tmp->parent=pr;
									   }
									   break;
							   }
						   }
					   }
					   private: void Print(BiTree *root,Pen ^ pen,int x1,int y1,int x2,int y2){
									if(root==0x0)return;
									SolidBrush ^ br=gcnew SolidBrush(Color::Red);
									SolidBrush ^  brc=gcnew SolidBrush(Color::Blue);
									System::Drawing::Font ^ ft = gcnew System::Drawing::Font("Time New Norman", 15);

									int h=50,w=250,s=15,s2=5;
									if(root->layer>1) g->DrawLine(pen,x1,y1,x2,y2);
									g->FillEllipse(brc,x2-s,y2-s,2*s,2*s);
									g->FillEllipse(brc,x1-s,y1-s,2*s,2*s);
									g->DrawString(String::Format("{0}",root->data),ft,br,x2-s/1.5,y2-s/1.5);
									if(root->parent!=0x0)g->DrawString(String::Format("{0}",root->parent->data),ft,br,x1-s/1.5,y1-s/1.5);
									x1=x2;y1=y2;
									if(root->Lchild){
										root->Lchild->layer=root->layer+1;
										
										x2=x1-w*Math::Pow(2,-root->layer);
										y2=y1+h;
										Print(root->Lchild,pen,x1,y1,x2,y2);
									}
									if(root->Rchild){
										root->Rchild->layer=root->layer+1;
										x2=x1+w*Math::Pow(2,-root->layer);
										y2=y1+h;
										Print(root->Rchild,pen,x1,y1,x2,y2);
									}										

								}
	private: System::Void buttonCreatTree_Click(System::Object^  sender, System::EventArgs^  e) {
				 String ^ s=this->textBoxBiTree->Text->Trim();
				 root= DSchen::Form1::CreateBitree(s);
				this->pictureBox1->Width=600;
				Pen ^ pen=gcnew Pen(Color::Red);
									this->pictureBox1->Height=800;
									this->pictureBox1->Top=250;
									this->pictureBox1->Left=50;
									this->pictureBox1->Refresh();
									 g=this->pictureBox1->CreateGraphics();
									 root->layer=1;
									
									 pen->Color=Color::Blue;
									 Print(root,pen,300,40,300,40);
			 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 this->groupBoxTree->Top=5000;
		 }
private: System::Void 先序遍历ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 SolidBrush ^ br=gcnew SolidBrush(Color::Red);
			System::Drawing::Font ^ ft = gcnew System::Drawing::Font("Time New Norman", 15);
			Pen ^ pen=gcnew Pen(Color::Red);
			this->pictureBox1->Refresh();
			ft->Bold::get();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -