计算机软件实验报告1

上传人:ji****n 文档编号:45704282 上传时间:2018-06-18 格式:DOC 页数:21 大小:359KB
返回 下载 相关 举报
计算机软件实验报告1_第1页
第1页 / 共21页
计算机软件实验报告1_第2页
第2页 / 共21页
计算机软件实验报告1_第3页
第3页 / 共21页
计算机软件实验报告1_第4页
第4页 / 共21页
计算机软件实验报告1_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《计算机软件实验报告1》由会员分享,可在线阅读,更多相关《计算机软件实验报告1(21页珍藏版)》请在金锄头文库上搜索。

1、实验一实验一 顺序存储的线性表维护子系统的实现顺序存储的线性表维护子系统的实现实验报告实验报告姓名姓名: 朱安国 学号学号: 11005A0516 日期:日期:2011/11/25 一、实验程序一、实验程序#include#include #define#define maxmax 8 8intint last=8;last=8;intint nodemax=4,2,6,10,19,14,16,21;nodemax=4,2,6,10,19,14,16,21;intint main()main() intint i,a,x,c,p,flag=0,r,s,u,v;i,a,x,c,p,flag=0,

2、r,s,u,v;intint find(intfind(int x);x);voidvoid insert(intinsert(int p,intp,int x);x);voidvoid delete(intdelete(int p);p);voidvoid paixu(void);paixu(void);voidvoid modify(intmodify(int p,intp,int x);x);printf(“pleaseprintf(“please enterenter number:nnumber:n 查找某个值的节点请输查找某个值的节点请输 1n1n 删除某个节点删除某个节点 (小于

3、(小于 8 8)请输)请输 2n2n 修改节点(小于修改节点(小于 8 8)的值请输)的值请输 3n3n 节点(小于节点(小于 8 8)之前插入数据请输)之前插入数据请输 4n4n 对线性表进行排序请输对线性表进行排序请输 5n“);5n“);scanf(“%d“,scanf(“%d“,switch(a)switch(a) casecase 1:1:printf(“pleaseprintf(“please enterenter thethe xn“);xn“);scanf(“%d“,scanf(“%d“,c=find(x);c=find(x);if(c=-1)if(c=-1)printf(“n

4、oprintf(“no findn“);findn“);elseelseprintf(“findprintf(“find result=%dn“,c);result=%dn“,c);break;break;casecase 2:2:printf(“pleaseprintf(“please enterenter thethe deletedelete potpot pn“);pn“);scanf(“%d“,scanf(“%d“,printf(“beforeprintf(“before deleten“);deleten“);for(i=0;ilast-1|plast-1|pnodej)if(no

5、deinodej) t=nodei;t=nodei;nodei=nodej;nodei=nodej;nodej=t;nodej=t; voidvoid modify(intmodify(int p,intp,int x)x) nodep=x;nodep=x; voidvoid insert(intinsert(int p,intp,int x)x) intint m;m;if(last=max)if(last=max)printf(“theprintf(“the listlist isis full!n“);full!n“);elseelse for(m=last-1;m=p;m-)for(m

6、=last-1;m=p;m-)nodem+1=nodem;nodem+1=nodem;nodep=x;nodep=x;last=last+1;last=last+1; 二、实验过程二、实验过程本程序建立了顺序存储的线性表的查找,插入,删除,修改,排序各段的子程序,主函数本程序建立了顺序存储的线性表的查找,插入,删除,修改,排序各段的子程序,主函数 调用个子函数构成该程序,得到现在的程序。调用个子函数构成该程序,得到现在的程序。三、实验分析三、实验分析建立线性表时,直接用数组赋初值。查找时,如果能找到时返回该值,找不到返回建立线性表时,直接用数组赋初值。查找时,如果能找到时返回该值,找不到返回-

7、1-1,输,输 出未找到。修改则是直接查找根节点,对数据值加以修改。插入时,找到指定的节点,当出未找到。修改则是直接查找根节点,对数据值加以修改。插入时,找到指定的节点,当 线性表满时,不能插入,当线性表不满时,可以插入。删除时,当线性表为空时或者删除线性表满时,不能插入,当线性表不满时,可以插入。删除时,当线性表为空时或者删除 位置不对时,不可删除,否则才可进行。排序才用冒泡法。位置不对时,不可删除,否则才可进行。排序才用冒泡法。四、实验结论四、实验结论1 1,查找,查找2 2,替换,替换3 3,删除,删除4 4,插入,插入5 5,排序,排序实验二实验二 二叉树的前序遍历程序的实现二叉树的前

8、序遍历程序的实现实验报告实验报告姓名:姓名: 朱安国朱安国 学号:学号: 11005A0516 日期:日期:2011/11/25 一、实验程序一、实验程序#include#include#include#include#define#define maxmax 1010structstruct nodenode intint data;data;structstruct nodenode *llink;*llink;structstruct nodenode *rlink;*rlink;voidvoid preorder(structpreorder(struct nodenode *t);*

9、t);main()main() structstruct nodenode *t,*s2,*s3,*s4,*s5;*t,*s2,*s3,*s4,*s5;t=(structt=(struct node*)malloc(sizeof(structnode*)malloc(sizeof(struct node);node);s2=(structs2=(struct node*)malloc(sizeof(structnode*)malloc(sizeof(struct node);node);s3=(structs3=(struct node*)malloc(sizeof(structnode*)m

10、alloc(sizeof(struct node);node);s4=(structs4=(struct node*)malloc(sizeof(structnode*)malloc(sizeof(struct node);node);s5=(structs5=(struct node*)malloc(sizeof(structnode*)malloc(sizeof(struct node);node);t-data=5;t-data=5;s2-data=6;s2-data=6;s3-data=9;s3-data=9;s4-data=11;s4-data=11;s5-data=2;s5-dat

11、a=2;t-llink=s2;t-llink=s2;t-rlink=s3;t-rlink=s3;s2-llink=s4;s2-llink=s4;s2-rlink=NULL;s2-rlink=NULL;s3-llink=s5;s3-llink=s5;s3-rlink=NULL;s3-rlink=NULL;s4-llink=NULL;s4-llink=NULL;s4-rlink=NULL;s4-rlink=NULL;s5-llink=NULL;s5-llink=NULL;s5-rlink=NULL;s5-rlink=NULL;preorder(t);preorder(t);return(0);re

12、turn(0); voidvoid preorder(structpreorder(struct nodenode *t)*t) structstruct nodenode *smax;*smax;structstruct nodenode *p;*p;intint top;top;top=-1;top=-1;p=t;p=t;dodo while(p!=NULL)while(p!=NULL) printf(“%dprintf(“%d “,p-data);“,p-data);if(p-rlink!=NULL)if(p-rlink!=NULL) top=top+1;top=top+1;stop=p

13、-rlink;stop=p-rlink; p=p-llink;p=p-llink; if(top!=-1)if(top!=-1) p=stop;p=stop;top=top-1;top=top-1; while(p!=NULL)|(top!=-1);while(p!=NULL)|(top!=-1); 二、实验过程二、实验过程先用赋值法建立一颗二叉树,然后按照访问根节点,遍历左子树,遍历右子树的顺序,遍先用赋值法建立一颗二叉树,然后按照访问根节点,遍历左子树,遍历右子树的顺序,遍 历这颗二叉树,输出遍历结果。历这颗二叉树,输出遍历结果。三、实验分析三、实验分析在二叉树的建立时,以所输入的字母为其

14、数据项;遍历时,打印相应的节点值。在二叉树的建立时,以所输入的字母为其数据项;遍历时,打印相应的节点值。四、实验结论四、实验结论实验三实验三 二叉排序树维护子系统实现二叉排序树维护子系统实现实验报告实验报告姓名:姓名: 朱安国朱安国 学号:学号: 11005A0516 日期:日期: 2011/11/25 一、实验程序一、实验程序#include#include #include#include #define#define MAXMAX 1010typedeftypedef structstruct nodenode intint data;data;structstruct nodenode

15、 *llink;*llink;structstruct nodenode *rlink;*rlink;node;node;nodenode *root;*root;voidvoid print_node(node*print_node(node* p);p);voidvoid print_tree(node*print_tree(node* p);p);intint insert(intinsert(int x)x) node*p,*q;node*p,*q;if(root=NULL)if(root=NULL) root=(node*)malloc(sizeof(node);root=(node*)malloc(sizeof(node);root-data=x;root-data=x;root-rlink=NULL;root-rlink=NULL;root-llink=N

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 初中教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号