非递归的排序

本文介绍了两种不同的二叉树遍历方法:一种是中序遍历,通过递归方式利用辅助数组实现;另一种则是使用标记的方法进行中序遍历,同样采用递归思想和辅助数组来跟踪节点的状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void put1(data top)
{
 data point[30],temp = top;
 int p = -1;
 if(temp == NULL)
  cout<<"二叉树为空:";
 else
 {
  do
  {
   while(temp)
   {
    point[++p] = temp;
    temp = temp ->left;
   }
   temp = point[p--];
   cout<<temp ->num<<' ';
   temp = temp ->right;
  }while(!(temp == NULL&& p == -1));
 }
}

void put2(data top)
{
 data point[30],temp = top;
 int p = -1,a;
 int pp[30];
 if(top == NULL)
  cout<<"二叉树为空!";
 else
 {
  do
  {
   while(temp)
   {
    point[++p] = temp;
    pp[p] == 0;
    temp = temp ->left;
   }
   temp = point[p];
   a = pp[p--];
   if(a == 0)
   {
    point[++p] = temp;
    pp[p] = 1;
    temp = temp ->right;
   }
   else
   {
    cout<<temp ->num<<' ';
    temp = NULL;
   }
  }while(!(temp == NULL && p == -1));
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值