首页 > 试题广场 >

二叉排序树

[编程题]二叉排序树
  • 热度指数:44501 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
输入一系列整数,建立二叉排序树,并进行前序,中序,后序遍历。

输入描述:
输入第一行包括一个整数n(1<=n<=100)。
接下来的一行包括n个整数。


输出描述:
可能有多组测试数据,对于每组数据,将题目所给数据建立一个二叉排序树,并对二叉排序树进行前序、中序和后序遍历。
每种遍历结果输出一行。每行最后一个数据之后有一个换行。

输入中可能有重复元素,但是输出的二叉树遍历序列中重复元素不用输出。
示例1

输入

5
1 6 5 9 8

输出

1 6 5 9 8 
1 5 6 8 9 
5 8 9 6 1 
头像 不红红黑路同
发表于 2022-02-28 15:00:56
#include <iostream> #include <queue> using namespace std; //二叉排序树二 struct TreeNode{ int data; TreeNode *leftchild; TreeNode 展开全文
头像 yyer
发表于 2023-02-10 10:35:30
#include <iostream> using namespace std; struct TreeNode{ int data; TreeNode* left; TreeNode* right; }; TreeNode* build(TreeNode* ro 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-07 11:39:07
#include <bits/stdc++.h> using namespace std; typedef struct BiTNode { int data; struct BiTNode* lchild, *rchild; } BiTNode, *BiTree; 展开全文
头像 鱼儿恋上水
发表于 2020-03-14 23:38:23
#include <iostream> #include <cstdio> using namespace std; struct node { int val; node *left, *right; node(int v):val(v),left( 展开全文
头像 Coming680
发表于 2022-02-10 11:49:05
#include<iostream> using namespace std; typedef struct node { int num; struct node* left, * right; node(int n) :num(n), left(NULL), 展开全文
头像 牛客745135892号
发表于 2024-03-05 20:12:18
#include<iostream> #include<stdlib.h> using namespace std; typedef struct node { int val; struct node* left, *right; }* bittree, 展开全文
头像 MountainsHao
发表于 2024-03-17 11:00:31
#include <stdio.h> #include <stdlib.h> // 定义二叉树节点结构 typedef struct Node { int data; struct Node* left; struct Node* right; } 展开全文
头像 牛客784280659号
发表于 2024-03-04 17:43:25
#include <cstddef> #include <iostream> using namespace std; struct Node { Node *left; Node *right; int val; Node(int x):v 展开全文
头像 上林清风
发表于 2023-05-04 11:02:46
#include<iostream> #include<cstring> using namespace std; int arr[101]; typedef struct BiTNode { int data; struct BiTNode* L, * R; 展开全文
头像 帅呆呆~
发表于 2022-03-12 18:09:20
#include<iostream> #include<cstdio> #include<string> using namespace std; struct TreeNode { int data; TreeNode* leftChild; Tree 展开全文

问题信息

难度:
192条回答 17334浏览

热门推荐

通过挑战的用户

查看代码