已知二叉树先序和中序序列 求后序序列

源码如下:

void test(std::string str1,std::string str2,int length)
{
	if(str1.empty()&&str2.empty())
		return;
	s.push(str1.c_str()[0]);
	int count=str2.find_first_of(s.top());
	std::string str11,str22;
	count++;
	str11=str1.substr(count,length-count);
	str22=str2.substr(count,length-count);
	test(str11,str22,str11.length());
	str11=str1.substr(1,--count);
	str22=str2.substr(0,count);
	test(str11,str22,str22.length());
}



int main()
{
	test("abcdefopghi","dcebofpahgi",11);
	while(!s.empty())
	{
		cout<<s.top()<<" ";
		s.pop();
	}
}


递推公式

test(*str)

{

     if(!str) return;

      push_back(str[0]);

      substr=右子树;

      test(substr);

      substr=左子树;

      test(substr);

}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值