zoukankan      html  css  js  c++  java
  • PAT:1064. Complete Binary Search Tree (30) AC

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    const int MAX=1010;
    int n;
    int arr[MAX];      //存放原始数组
    int arrI=0;
    int CBT[MAX];      //二叉排序树层序遍历序列【思维】中序遍历在数组中存放的就是层序遍历序列
    
    void inorder(int root)
    {
      if(root>n)
        return;
      inorder(root*2);
      CBT[root]=arr[arrI++];
      inorder(root*2+1);
    }
    
    int main()
    {
      scanf("%d",&n);
      for(int i=0 ; i<n ; ++i)
        scanf("%d",&arr[i]);
      sort(arr,arr+n);
      inorder(1);          //【caution】千万不能写成0,写成0的话*2永远都是0.牺牲CBT[0],从1开始
      for(int i=1 ; i<n ; ++i)
        printf("%d ",CBT[i]);
      printf("%d
    ",CBT[n]);
      return 0;
    }
  • 相关阅读:
    hdu5249
    hdu5673-Robot
    hihoCoder 1033
    simpleOS 1.0
    hdu3511-Prison Break
    单调栈
    关于每次取PC的值为PC+4的问题
    hdu3652
    Linux MySQL5.7.18安装手册
    Linux MySQL5.6.36安装手册
  • 原文地址:https://www.cnblogs.com/Evence/p/4321911.html
Copyright © 2011-2022 走看看