二叉树结构的文本模式显示

2012-04-29 13:17:14江顺亮任燕
电脑知识与技术 2012年16期

江顺亮 任燕

摘要:二叉树在数据结构的教学中是非常重要的一类非线性结构,在上机编程和调试的过程中如何快速有效直观地显示这类非线性结构直接影响着教与学的效率,为此提出了一种文本模式的二叉树结构显示方法;该方法利用_、/和三种特殊字符把子结点和父结点连接起来,使用队列对二叉树进行层序输出。在队列中采用空指针NULL代表空结点,同时用一个新结点end表示每一层的结束。该方法不仅适用于顺序存储的二叉树也适用于链式存储的二叉树,进行适当修改也可顺利地显示3阶B_树,因此可以作为数据结构教与学的有效手段之一。

关键词:二叉树;显示;文本模式

中图分类号:TP311文献标识码:A文章编号:1009-3044(2012)16-3856-05

Text-mode Display of Binary Tree

JIANG Shun-liang, REN Yang

(Department of Computer Science and Technology, School of Information Engineering, Nanchang University, Nanchang 330031, China) Abstract: Binary tree is very important nonlinear structure in the data structures, how to display the binary tree effectively is essential to the related teaching and learning. A text-mode display method for binary tree was proposed, three characters (‘_,‘/and‘) were used to connect the parent and children nodes, queue technique was used to export binary tree by level-order, the empty node is represented by the NULL pointer and one new node is created to denote the end of one level in the level-order queue. The method is usable for both of sequence and linked binary trees, is applicable for display of 3-order B_tree by small modification, and is valuable to improve the teaching and learning.

Key words: Binary tree; display; Text-mode

数据结构是计算机科学与技术学科的16门核心课程之一[1],它对培养学生的两项专业能力:算法设计与分析的能力、程序设计能力[1]是非常重要的。数据结构也是全国硕士研究生入学统一考试计算机科学与技术学科综合专业的重要部分,其分数占总分的近三分之一。二叉树是数据结构中非常基础的非线性结构,对学好其它非线性结构具有重要的作用。非线性结构的算法与程序设计对于初学者来说是比较抽象的,即使象二叉树这样简单与基础的非线性结构,要掌握它也不是一件容易的事;学好它离不开动脑与动手,上机编程和调试相关算法非常重要,但是学生不易直观检查计算结果,这会影响调试的效率。……

登录APP查看全文