(4)用递归和非递归的方法写出树的先序遍历,需为可执行的代码。
给出结点定义
class tree
{
public:
int data;
class tree *left, *right;
};
typedef class tree node;
typedef node *bitree;
为了方便coding,给出stock栈操作,push(PNode);pop();
(5)一个M*M的矩阵A,一个字符串数组S,比较S中的字符串是否在A中的连续对角线序列 ** 现。
譬如一个4*4的矩阵 1 2 3 4
a b c d
5 6 7 8
e f g h
则其连续对角线从左算:1 2 a 5 b 3 4 c 6 e f 7 d 8 g h
或 1 a 2 3 b 5 e 6 c 4 d 7 f g 8 h
从右算:4 3 d 8 c 2 1 b 7 h g 6 a 5 f e
或 4 d 3 2 c 8 h 7 b 1 a 6 g f 5 e
(a)(b)两问,大概是写出优化高效的算法,不一定要程序,可用流程图或者文字描述,简述算法原理,计算时间复杂度。