/******************************************************************
题目: 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. Java 异步处理简单实践

    Java 异步处理简单实践 http://www.cnblogs.com/fangfan/p/4047932.html 同步与异步 通常同步意味着一个任务的某个处理过程会对多个线程在用串行化处理,而异 ...

  2. 操作配置文件Properties

    // */ // ]]>   操作配置文件Properties Table of Contents 1 定义 2 读取配置值 3 修改和保存配置 4 注意 1 定义 csharp中在Settin ...

  3. [zz] 英文大写缩写前要加THE吗

    http://zhidao.baidu.com/link?url=BvXRdoE0OjGh46rlodbyM3wirORSGGcnYGq0xYEtcoIMTkLnXd4Hl3iMLbKNb2npRdI ...

  4. SQL Server 2012 创建数据库快照

    不是所有的MSSQL数据库版本都支持数据库快照,只有Enterprise版本的才支持. 在其他版本上,以Business Intelligence Edition版本为例,创建快照时,会报如下错误 消 ...

  5. VS2010 + Entity FrameWork 4.4 +Mvc 4.0 出现的错误

    Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined i ...

  6. Spring AOP 完成日志记录

    Spring AOP 完成日志记录 http://hotstrong.iteye.com/blog/1330046

  7. 就是这么简单!使用Rest-assured 测试Restful Web Services

    使用 Rest-assured 测试 Restful Web Services 转载注明出处: http://www.cnblogs.com/wade-xu/p/4298819.html 这里向大家介 ...

  8. (LinkedList)Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  9. Chap2: question: 1 - 10

    1. 赋值运算符函数(或应说复制拷贝函数问题) class A { private: int value; public: A(int n) : value(n) {} A(A O) { value ...

  10. javascript MVC(每天有学习一点篇)

    “写的不是代码,是你的思维”,经常觉得自己写的代码“皮粗肉糙”的,看到那些要么精致小巧,要么优雅大方,要么光明磊落的代码时,常常会黯然神伤外加垂涎欲滴. why?(为什么我的代码不能如此..) whe ...