文章

19

粉丝

21

获赞

5

访问

13.1k

头像
暑假机试训练--Day14
综合
发布于2023年8月27日 12:17
阅读数 479

树专题1(PAT):

1.树叶子结点

树叶子结点

 

2.树的遍历

树的遍历

 

3.最深的根

最深的根

 

4.判断二叉搜索树

判断二叉搜索树

 

5.完全二叉搜索树

完全二叉搜索树

 

6.再次树遍历

再次树遍历

 

7.构建二叉搜索树

构建二叉搜索树

 

8.反转二叉树

反转二叉树

 

9.完全二叉树

完全二叉树

 

10.二叉搜索树最后两层结点数量

二叉搜索树最后两层结点数量

 

11.前序和后序遍历

前序和后序遍历

 

12.Z字形遍历二叉树

Z字形遍历二叉树

 

AC代码:

1.树叶子结点

# include <bits/stdc++.h>
using namespace std;
const int N = 110;

int h[N],e[N],ne[N],idx = 0;
int n,m,max_floor = 0;
int cnt[N];

void add(int a,int b){
  e[idx] = b,ne[idx] = h[a],h[a] = idx ++;
}

void dfs(int u,int f){
  max_floor = max(max_floor,f);
  
  if (h[u] == -1){
    cnt[f] ++;
    return;
  }
  
  for (int i = h[u]; i != -1; i = ne[i]){
    int j = e[i];
    dfs(j,f + 1);
  }
}

int main (void){
  memset(h, -1 ,sizeof h);
  memset(cnt, 0 ,sizeof cnt);
  scanf("%d%d",&n,&m);
  
  while (m --){
    i...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发