云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 学位论文-—双向循环链表的创建及相关操作的实现课程设计说明书

学位论文-—双向循环链表的创建及相关操作的实现课程设计说明书

  • 62 次阅读
  • 3 次下载
  • 2025/6/16 22:49:48

山东建筑大学计算机学院课程设计说明书

exchangeTree(rootNode); } }

private BiTNode exchangeTree(BiTNode t) { if (t != null) {

BiTNode p = t.right; t.right = t.left; t.left = p;

exchangeTree(t.right); exchangeTree(t.left); }

return t;

}

// 计算树的深度

public int depth() {

return depth(rootNode); }

private int depth(BiTNode t) { // 返回二叉树的深度 int depthleft, depthright; if (t == null) return 0;

depthleft = depth(t.left); depthright = depth(t.right);

return Math.max(depthleft, depthright) + 1; }

//横向输出树状图

public void showTree(BiTNode t,int n){ if (t==null) return; showTree(t.right,++n);

for (int i = 0; i < n; i++) System.out.print(\); System.out.print(t.data+\); showTree(t.left,n++); } }

24

山东建筑大学计算机学院课程设计说明书

3.测试函数 package kcsj;

public class Test {

public static void pln(Object o) {

System.out.println(o); }

public static void main(String[] args) {

BinaryTree bt = new BinaryTree(); Character[] charsPre = { 'a', 'b', 'd', null, null, null, 'c', 'e', null, null, 'f' };

Character[] charsPath = { 'a', 'b', 'c', 'd', null, 'e', 'f' };

pln(\先序建树:{'a','b','d',null,null,null,'c','e',null,null,'f'}\); bt.creatTree(charsPre); pln(\层序遍历结果:\); bt.pathOrder();

pln(\);

pln(\树图为(横向):\);

bt.showTree(bt.rootNode, 1); pln(\);

pln(\层序建树:{'a','b','c','d',null,'e','f'}\); bt.creatPathTree(charsPath); pln(\先序遍历结果:\); bt.preOrder(); pln(\);

pln(\树图为(横向):\);

bt.showTree(bt.rootNode, 1); pln(\);

pln(\叶子节点数:\ + bt.countLeafNode()); pln(\交换后层次遍历结果:\); bt.exchangeTree(); bt.pathOrder(); pln(\);

25

山东建筑大学计算机学院课程设计说明书

}

}

pln(\树图为(横向):\); bt.showTree(bt.rootNode, 1); pln(\);

pln(\深度为:\ + bt.depth());

五、测试数据

1、对每个函数的测试数据

利用线序遍历和层次遍历分别建树a b c d e f 2、对程序整体的测试数据 a b c d e f

六、测试情况

先序建树:{'a','b','d',null,null,null,'c','e',null,null,'f'} 层序遍历结果: a b c d e f 树图为(横向): f c e a b d

层序建树:{'a','b','c','d',null,'e','f'} 先序遍历结果: a b d c e f 树图为(横向): f c e a b d

26

山东建筑大学计算机学院课程设计说明书

叶子节点数:3

交换后层次遍历结果: a c b f e d 树图为(横向): d b a

e c f

深度为:3

27

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

山东建筑大学计算机学院课程设计说明书 exchangeTree(rootNode); } } private BiTNode exchangeTree(BiTNode t) { if (t != null) { BiTNode p = t.right; t.right = t.left; t.left = p; exchangeTree(t.right); exchangeTree(t.left); } return t; } // 计算树的深度 public int depth() { return depth(rootNode

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com