|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
题目:在内存中构建一个10叉非完全树T10,树的高度为7,叶子节点的高度差最多为1,将该树T10存储到一个树存储文件Ftree中去。编写读树文件Ftree的程序,将树读入到内存中来,并且检验树的正确性。0 U1 X8 S/ X+ ^, P6 D# N) i; B
性能分析说明:& U. e: @% W! x3 g8 ~/ j
1.空间复杂度
0 J: ?7 p: r9 c( J& U* Y3 R2.文件大小+ P/ P8 M! X$ `# [: A
3.内存重构树的时间。
7 Z! S; D$ Z( m. X1 n3 b# p: C D0 g8 t9 i7 R7 e. K
: _+ ~( T& B3 J) Q; s6 [源码上上来,振振精神 A# v. h* N( l
, y3 t* L( X( c& H; U$ B1.程序源码6 K, n S) }7 d: t5 @' I
& s+ d, t7 m) ]) p(1)创建10叉非完全数的程序源码5 S1 K% @7 W$ K7 r P# _# r: Y
1 F9 ]( J/ k c0 e+ e- //ProgARM one:creat the tree
- #include<stdio.h>
- #include<stdlib.h>
- #define TEN 10
- #define MAXLEVEL 8
- typedef structTreeNode *TenTree;
- struct TreeNode{
- int data;
- TenTree children[TEN];
- }NTree;
- int num = 1;
- voidpreorder(TenTree ptr)
- {
- if (ptr){
- printf("%d ",ptr->data);
- for (int i = 0; i < TEN; i++){
- preorder(ptr->children);
- }
- } else {
- printf("0 ");
- }
- }
- TenTreeCreatTree(int level)
- {
- TenTree T;
- if (level == MAXLEVEL){
- T = NULL;
- return T;
- }
- T = (TenTree)malloc(sizeof(NTree));
- T->data = num++;
- for (int i = 0; i < TEN; i++){
- T->children = CreatTree(level+1);
- }
- return T;
- }
- int main()
- {
- TenTree T;
- T = CreatTree(1);
- preorder(T);
- return 0;
- }3 x t, s) {) R$ N6 y. b1 f# T
8 j, S6 R5 V/ f9 A: i! t |
|