摘要:
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。 输入格式: 输入包含若干组 阅读全文
摘要:
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 阅读全文
摘要:
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file contains one t 阅读全文
摘要:
#include #define MaxTree 12 #define ElementType char #define Null -1 #define Tree int struct TreeNode { ElementType element; Tree left; Tree right; }t1[MaxTree], t2[MaxTree]; Tree build... 阅读全文
摘要:
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given s 阅读全文
摘要:
1 #include <cstdio> 2 #include <stdlib.h> 3 typedef struct Node* Polynomial; 4 struct Node { 5 int coef; 6 int expon; 7 Polynomial next; 8 }; 9 10 voi 阅读全文
摘要:
1 #include <cstdio> 2 #define Null -1 3 4 const int maxn = 1e5+2; 5 struct Node { 6 int data; 7 int addr, next; 8 } Lst[maxn]; 9 10 11 12 int input(in 阅读全文
摘要:
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1. The Max 阅读全文
摘要:
#include const int MAXN = 1e5 + 2; int MaxSubseqSum(int a[], int n) { int ThisSum = 0, MaxSum = 0; for (int i=0; i MaxSum) { MaxSum = ThisSum; } else if (T... 阅读全文