/******************************************************************
题目: The order of a Tree(hdu 3999)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=3999
题意: 给你一个序列建立一棵二叉搜索树 要你找出另外一个序
列,可以建立和原序列建立的二叉搜索树一样且这个序列
是字典序最小
算法: 二叉搜索树
思想: 对于一个二叉搜索树,它的先序遍历是能建立该二叉搜索
树字典序最小序列
******************************************************************/
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std; typedef struct Tree
{
Tree *left,*right;
int num;
}Tree;
Tree *t; Tree *inser(Tree *p,int x)
{
if (p==NULL)
{
p=(Tree *) malloc(sizeof(Tree));
p->left=p->right=NULL;
p->num=x;
return p;
}
if (p->num>x)
{
p->left=inser(p->left,x);
return p;
}
else
{
p->right=inser(p->right,x);
return p;
}
} void Find(Tree *p,int flag)
{
if (p==NULL) return ;
if (flag) printf("%d",p->num);
else printf(" %d",p->num);
Find(p->left,);
Find(p->right,);
delete(p);
} int main()
{
int n;
while (~scanf("%d",&n))
{
t=NULL;
for (int i=;i<n;i++)
{
int a;
scanf("%d",&a);
t=inser(t,a);
}
Find(t,);
printf("\n");
}
}

hdu 3999 The order of a Tree (二叉搜索树)的更多相关文章

  1. HDU 3999 The order of a Tree 二叉搜索树 BST

    建一个二叉搜索树,然后前序输出. 用链表建的,发现很久没做都快忘了... #include <cstdio> #include <cstdlib> struct Node{ i ...

  2. <hdu - 3999> The order of a Tree 水题 之 二叉搜索的数的先序输出

    这里是杭电hdu上的链接:http://acm.hdu.edu.cn/showproblem.php?pid=3999  Problem Description: As we know,the sha ...

  3. HDU 3999 The order of a Tree (先序遍历)

    The order of a Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. PAT甲级——1099 Build A Binary Search Tree (二叉搜索树)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90701125 1099 Build A Binary Searc ...

  5. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  6. 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...

  7. [LeetCode] 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  8. [LeetCode] 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  9. [LeetCode]501. Find Mode in Binary Search Tree二叉搜索树寻找众数

    这次是二叉搜索树的遍历 感觉只要和二叉搜索树的题目,都要用到一个重要性质: 中序遍历二叉搜索树的结果是一个递增序列: 而且要注意,在递归遍历树的时候,有些参数如果是要随递归不断更新(也就是如果递归返回 ...

随机推荐

  1. 完成一段简单的Python程序,用于实现一个简单的加减乘除计算器功能

    #!/bin/usr/env python#coding=utf-8'''完成一段简单的Python程序,用于实现一个简单的加减乘除计算器功能'''try: a=int(raw_input(" ...

  2. C#创建datatable

    Asp.net DataTable添加列和行的方法 方法一: DataTable tblDatas = new DataTable("Datas"); DataColumn dc ...

  3. 怎么 才能显示Eclipse中Console的全部内容

    可以如下设置 preference->run/debug->console 设置limit console output 为false,方便调试时,查看全部console. 这个真是太有用 ...

  4. HackerRank "Larry's Array"

    I caught the sparkle in my mind and got AC1 ! It is a great great experience ! So the basic idea: pe ...

  5. Charles 3.11.5 绿色特别版

    Charles 3.11.5 绿色特别版,注册码在key文本中 链接: http://pan.baidu.com/s/1hsoFcyS 密码: q6e1

  6. JAVAWEB监听器(二)

    监听域对象中属性的变更的监听器 域对象中属性的变更的事件监听器就是用来监听 ServletContext, HttpSession, HttpServletRequest 这三个对象中的属性变更信息事 ...

  7. loadrunner 功能详解(一) - Run-time Settings

    1.General / Run Logic  Number of Iterations:说明的是反复循环的次数. 常境的时间中,如果时间设为5分钟,而实际上程序的运行只需要1分钟,而在这项中,选择的是 ...

  8. c# 串口编程

    http://news.ccidnet.com/art/32859/20100524/2067861_4.html 字节缓冲器处理类: /// <summary> /// 字节缓冲器 // ...

  9. safari渲染Transition动画不流畅问题

    用css3的transition过渡来做页面动画的时候,发现在chrome和ff流畅,在safari 不流畅: 度娘找到了淘宝UED的一个类似解决方案,动画就流畅了. 测试环境: win7 32bit ...

  10. IT在线笔试总结(一)

    综述:IT公司的技术类笔试,主要考察: (1)知识面的广度.主要考察一些业内通用性的知识,以及某一职务所必须具备的业务知识. (2)智力测试.主要考察记忆力,思维能力和学习新知识的能力. (3)技能测 ...