数据结构 树的应用.doc_第1页
数据结构 树的应用.doc_第2页
数据结构 树的应用.doc_第3页
数据结构 树的应用.doc_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

数据结构实验报告实验三、树结构的应用 一、实验目的 熟练掌握二叉树的存储结构以及进行遍历的各种算法,并根据实际问题的要求灵活运用。二、实验内容本次实验仍以班级学生信息作为管理对象,以学生信息中的学生成绩为关键字,生成一棵二叉排序树,查找特定结点。三、完成情况 typedef int KeyType;typedef struct node KeyType score; char num8; char name8; char gender3; struct node *lchild,*rchild;BSTNode;typedef BSTNode *BSTree;void InsertBST(BSTree *q,BSTNode *student) BSTNode *f,*p=*q; while(p) f=p; p=(student-score)score)?p-lchild:p-rchild; p=(BSTNode *)malloc(sizeof(BSTNode); p-score=student-score; strcpy(p-num,student-num); strcpy(p-name,student-name); strcpy(p-gender,student-gender); p-lchild=p-rchild=NULL; if(*q=NULL) *q=p; else if(student-scorescore) f-lchild=p; else f-rchild=p;BSTree CreateBST(void) BSTree T=NULL; BSTNode *student; int a=1; student=(BSTNode *)malloc(sizeof(BSTNode); printf(请输入学生信息:n); while (a) printf(学号t姓名t性别t成绩n); scanf(%s%s%s%d,student-num,student-name,student-gender,&student-score); InsertBST(&T,student); printf(继续? 1=是 0=否n); scanf(%d,&a); return T;void InOrder(BSTree root) if (root!=NULL) InOrder(root-lchild); printf(%st%st%st%dn,root-num,root-name,root-gender,root-score); InOrder(root-rchild); BSTNode *SearchBST(BSTree T,KeyType stuScore) if(T=NULL | stuScore=T-score) return T; if(stuScorescore) return SearchBST(T-lchild,stuScore); if(stuScoreT-score) return SearchBST(T-rchild,stuScore);void main() BSTree root; BSTNode *student; KeyType stuScore; printf(n生成二叉排序树:n); root=CreateBST(); printf(n中序遍历二叉排序树,输出结果n); printf(n学号(8) 姓名(8) 性别(3) 成绩n); printf(-n); InOrder(root); printf(n利用二叉排序树进行查找:n); printf(n请输入要查询的学生成绩:n); scanf(%d,&stuScore); student=SearchBST(root,stuScore); if(!student) printf(没有查找到成绩为%d的学生); else printf(成绩为%d的学生信息:); printf(%s,%s,%s,%dn,student-num,student-name,student-gender,student-score); getchar();四、实验结果 五、问题与解决BSTree CreateBST函数中的循环部分起初总是执行出错,设置的循环判断语句没有起到作用,用的是字符型的,最后换成整形1、0对应是否判断得以解决。六、实验总结 通过编程更深刻了解了中序遍历的具体过程,以及程序内部的执行方法实验成绩评价项目评分等级独立完成完整的实验内容,结果完全正确,报告内容完整,排版整洁美观,能真实体现实际操作过程及遇到的问题。A完成实验,实验内容较为完整,结果正确,报告内容较为完整,排版较为整洁美观,能体现实际操作过程及遇到的问题。B

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论