1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      python中怎么分析循環(huán)遍歷二叉樹(shù)

      python中怎么分析循環(huán)遍歷二叉樹(shù),很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

      超過(guò)10余年行業(yè)經(jīng)驗(yàn),技術(shù)領(lǐng)先,服務(wù)至上的經(jīng)營(yíng)模式,全靠網(wǎng)絡(luò)和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務(wù)范圍包括了:網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡(luò)托管,小程序開(kāi)發(fā),微信開(kāi)發(fā),App定制開(kāi)發(fā),同時(shí)也可以讓客戶的網(wǎng)站和網(wǎng)絡(luò)營(yíng)銷(xiāo)和我們一樣獲得訂單和生意!

      前序遍歷

      struct Node
      {
      	Node*left;
      	Node*right;
      	int data;
      	Node(){ func; }
      };
      Node* create(Node*p, int depth)
      {	if (p && depth)
      	{
      		p->left = new Node;
      		p->right = new Node;
      		p->data = depth;
      		create(p->left, depth - 1);
      		create(p->right, depth - 1);
      	}	if (!depth)
      	{
      		p->left = nullptr;
      		p->right = nullptr;
      		p->data = depth;
      	}	return p;
      }
      void print1(Node*p)
      {	if (p)
      	{
      		cout << p->data << " ";
      		print1(p->left);
      		print1(p->right);
      	}
      }
      void print2(Node*head)//利用stack 模擬函數(shù)調(diào)用過(guò)程 來(lái)遍歷{
      	stack s;
      	Node*p = head;
      	{		while (p)
      		{
      			s.push(p);
      			cout << p->data << " ";
      			p = p->left;
      		}		while (!s.empty())
      		{
      			Node*pp = s.top();			if (pp->right && pp != head)
      			{
      				cout << pp->right->data << " ";
      			}
      			s.pop();
      		}
      	}
      	{
      		p = head->right;		while (p)
      		{
      			s.push(p);
      			cout << p->data << " ";
      			p = p->left;
      		}		while (!s.empty())
      		{
      			Node*pp = s.top();			if (pp->right
      				&& pp != head)
      			{
      				cout << pp->right->data << " ";
      			}
      			s.pop();
      		}
      	}
      }
      int main()
      {
      	Node* head = new Node;
      	create(head, 2);
      	head->data = 10;
      	head->left->data = 6;
      	head->right->data = 14;
      	head->left->left->data = 4;
      	head->left->right->data = 8;
      	head->right->left->data = 12;
      	head->right->right->data = 16;
      	print1(head);//遞歸遍歷
      	cout << endl;
      	print2(head);//循環(huán)遍歷
      	system("pause");	return 0;
      }

      中序

      void print2(Node*head)
      {
      	stack s;
      	Node*p = head;
      	{		while (p)
      		{
      			s.push(p);		//	cout << p->data << " ";
      			p = p->left;
      		}		while (!s.empty())
      		{
      			Node*pp = s.top();
      			cout << pp->data << " ";			if (pp->right && pp != head  )
      			{
      				
      				cout << pp->right->data << " ";
      			}
      			s.pop();
      		}
      	}
      	{
      		p = head->right;		while (p)
      		{
      			s.push(p);
      		
      			p = p->left;
      		}		while (!s.empty())
      		{
      			Node*pp = s.top();
      			cout << pp->data << " ";			if (pp->right&& pp != head)
      			{
      				cout << pp->right->data << " ";
      			}
      			s.pop();
      		}
      	}
      }

      后序

      void print2(Node*head)
      {
      	stack s;
      	Node*p = head;
      	{		while (p)
      		{
      			s.push(p);
      	
      			p = p->left;		
      		}		while (!s.empty())
      		{
      			Node*pp = s.top();	
      			if (pp->right && pp != head  )
      			{
      				
      				cout << pp->right->data << " ";
      			}	
      			if ( pp != head)
      			cout << pp->data << " ";
      			s.pop();
      		}
      	}
      	{
      		p = head->right;		while (p)
      		{
      			s.push(p);
      			p = p->left;
      		}		while (!s.empty())
      		{
      			Node*pp = s.top();		
      			if (pp->right&& pp != head)
      			{
      				cout << pp->right->data << " ";
      			}	
      			cout << pp->data << " ";
      			s.pop();
      		}
      	}
      	cout << head->data << " ";
      }

      看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。


      名稱欄目:python中怎么分析循環(huán)遍歷二叉樹(shù)
      網(wǎng)站鏈接:http://www.ef60e0e.cn/article/gedgcd.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        通渭县| 三明市| 寿光市| 太保市| 仙游县| 万载县| 顺平县| 宜春市| 宁城县| 汉寿县| 大悟县| 万载县| 壶关县| 朝阳市| 石棉县| 青海省| 尼玛县| 马龙县| 栾川县| 双牌县| 揭阳市| 婺源县| 南华县| 长寿区| 剑阁县| 郎溪县| 四会市| 永州市| 左权县| 黄龙县| 衢州市| 景谷| 柳州市| 普宁市| 庐江县| 峨眉山市| 扬州市| 开鲁县| 烟台市| 许昌县| 包头市|