非递归的排序

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));
 }
}

你可能感兴趣的:(非递归的排序)