
二叉树
coldfresh
那我们开始吧
展开
-
二叉平衡树(AVL)的插入
这次节点的数据域增加了高度这个量,用来计算平衡因子,以此在插入的时候来调整树的结构 节点:struct node{ int val; int hei; node *l; node *r;};构造新节点node* newNode(int v){ node* Node=new node; Node->val=v; N...原创 2018-03-06 19:14:00 · 252 阅读 · 0 评论 -
(pat)A1119. Pre- and Post-order Traversals
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences, or preorder and inorder ...原创 2018-03-14 09:56:47 · 354 阅读 · 0 评论 -
(pat)A1043. Is It a Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:1.The left subtree of a node contains only nodes with keys less than the node’s key. 2.The righ...原创 2018-03-06 17:54:10 · 202 阅读 · 0 评论 -
二叉搜索树(BST)的相关操作
今天写一写二叉搜索树的插入,查找,删除的操作。 首先给出节点的数据结构struct node{ int data; node*l; node* r;};第一个是查找操作:void search(node* root,int x){ if(root==NULL) { printf("no"); ret...原创 2018-03-06 16:25:20 · 215 阅读 · 0 评论 -
(pat)A1115. Counting Nodes in a BST
Counting Nodes in a BST (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Binary Search Tree (BST) is recursively defined as a binary tree which has the following ...原创 2018-03-13 18:30:17 · 234 阅读 · 0 评论 -
(pat)A1020. Tree Traversals
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the cor...原创 2018-03-05 20:45:50 · 196 阅读 · 0 评论 -
二叉树建树的若干问题
问题1二叉树有一种问题很经典,如果给出中序遍历和前序遍历的序列,如果建立一个颗二叉树数?(实际上后续遍历和前序遍历是一样的,可以替换掉前序遍历的)那么我们容易知道,前序遍历序列的第一个节点就是root,那么我们在中序遍历找出这个点,那么在这个店的做边就是左子树的中序遍历序列,右边亦然,那么前序遍历在除掉第一个点以后与左子树的中序遍历序列相同数量想对应,构成一个规模缩小,但是问题一致的子问题,所...原创 2018-03-05 17:59:17 · 330 阅读 · 0 评论 -
(pat)A1064. Complete Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:1.The left subtree of a node contains only nodes with keys less than the node’s key. 2.The righ...原创 2018-03-12 19:12:49 · 354 阅读 · 0 评论 -
(pat)A1099. Build A Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key. The right su...原创 2018-03-09 10:08:37 · 212 阅读 · 0 评论 -
(pat)A1138. Postorder Traversal
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal se...原创 2018-03-09 09:39:58 · 355 阅读 · 0 评论 -
(pat)A1086. Tree Traversals Again
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...原创 2018-03-08 23:03:39 · 198 阅读 · 0 评论 -
(pat)A1135. Is It A Red-Black Tree
There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black. (2) The root is black. (3) Every...原创 2018-03-14 19:58:07 · 425 阅读 · 0 评论 -
(pat)A1127. ZigZagging on a Tree
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple stand...原创 2018-03-14 12:03:08 · 307 阅读 · 0 评论