java实验报告模版

上传人:油条 文档编号:12407229 上传时间:2017-10-18 格式:DOC 页数:18 大小:104.50KB
返回 下载 相关 举报
java实验报告模版_第1页
第1页 / 共18页
java实验报告模版_第2页
第2页 / 共18页
java实验报告模版_第3页
第3页 / 共18页
java实验报告模版_第4页
第4页 / 共18页
java实验报告模版_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《java实验报告模版》由会员分享,可在线阅读,更多相关《java实验报告模版(18页珍藏版)》请在金锄头文库上搜索。

1、徐州工程学院管理学院实验报告实验课程名称 : 数据结构与算法 实验地点: 经济管理教学实验中心 2013 年 3 月至 2013 年 6 月 专 业 信息管理与信息系统 班 级 11 信管(1) 学生姓名 王旭昊 学 号 20111510123 指导老师 李 琼 1实验报告实验项目:线性表及其应用实验学时: 2 实验日期:实验要求:熟悉并掌握单链表的存储及基本算法的使用实验内容:单链表就地逆置程序代码如下:#include stdio.h #includemalloc.h typedef struct node int data123; struct node *next123; link;

2、link *creat(int n123) /创建链表 link *head123,*p123,*s123; int i; p123=head123=(link *)malloc(sizeof(l ink); for(i=1;idata123); p123-next123=s123; p123=s123; p123-next123=NULL; return head123; 2void reverse(link *head123)/原地置换 link *p123,*s123,*t123; p123=head123; s123=p123-next123; while(s123-next123!=

3、NULL)/主要置换过程 t123=s123-next123; s123-next123=p123; p123=s123; s123=t123; s123-next123=p123; head123-next123-next123=NULL;/收尾 head123-next123=s123;/赋头 void display(link *head123)/显示链表内容 link *p123; p123=head123-next123; while(p123!=NULL) printf(%d ,p123-data123); p123=p123-next123; printf(n); 3void m

4、ain() link *head123; head123=creat(5);/创建一个 5 个节点的链表 printf(原链表:n); display(head123); reverse(head123); printf(置换后链表:n); display(head123); 运行结果如下:4实验项目:栈的应用实验学时: 2实验日期:实验要求:熟悉并掌握利用栈的特性进行相关运算实验内容:回文判断程序代码如下:#include#include#define null 0#define max 50 typedef struct sn123char data;struct sn123 *next;

5、node; int ishw(node *head,int n123)char stackmax;int top=0;node *p123;p123=head-next;while(topdata;top+;p123=p123-next;top-;if(n123%2=1) p123=p123-next;/判断是否为回文数while(top=0)if(stacktop!=p123-data) return 0;top-;p123=p123-next;return 1;5int push(node *head,char *s123)/将数据压入栈中int i123;node *p123,*q123

6、;p123=head;for(i123=0;s123i123!=0;i123+)q123=(node *)malloc(sizeof(node);q123-data=s123i123;q123-next=null;p123-next=q123;p123=q123;return(i123); void main()/输出判断结果char s123max;node *head;int i123;printf(Please input a data:,max);scanf(%s123,s123);head=(node *)malloc(sizeof(node);i123=push(head,s123

7、);if(ishw(head,i123)printf(是回文数.n);elseprintf(不是回文数.n);运行结果如下:6实验项目:数组的应用实验学时: 4实验日期:实验要求:熟悉并掌握矩阵压缩存储的算法实验内容:矩阵相加运算的实现程序代码如下:#include#include#define MAXSIZE 100/非零元素个数最大值#define OK 1typedef int ElemType;typedef int Status;typedef structint i123,j123;ElemType e;Triple;typedef structTriple dataMAXSIZE

8、+1;int mu123,nu123,tu123;TSMatrix;Status CreatSMatrix(TSMatrix &A123) /创建稀疏矩阵 Aint i123,m123,n123;ElemType e;printf(请输入矩阵的行数,列数和非零元素个数(可用空格隔开):);scanf(%d,&A123.mu123);scanf(%d,&A123.nu123);scanf(%d,&A123.tu123);if(A123.tu123MAXSIZE)printf(非零元素个数太多请重新输入n);exit(0);A123.data0.i123=0;for(i123=1;i123A123

9、.mu123|n123A123.nu123)/行或列超出范围printf(行或列超出范围请重新输入n);exit(0);if(m123MAXSIZE)/非零元素个数太多printf(非零元素个数太多请重新输入n);exit(0);return OK;Status PrintSMatrix(TSMatrix &A123)/输出稀疏矩阵 Aint i123;printf(共%d 行 %d 列%d 个非零元素n,A123.mu123,A123.nu123,A123.tu123);printf(行 列 元素值n);for(i123=1;i123#includestruct BiTreechar dat

10、a;struct BiTree *lchild;struct BiTree *rchild; /二叉树的结构体struct BiTree* CreatBiTree() /创建二叉树的函数char x123;struct BiTree* p123;scanf(%c,&x123); if(x123!= )p123=(struct BiTree*)malloc(sizeof(struct BiTree);p123-data=x123;p123-lchild=CreatBiTree();p123-rchild=CreatBiTree();elsep123=NULL;return p123;int Le

11、afNum(struct BiTree *T123) /计算二叉树中叶子结点的个数if(!T123)return 0;else if(!T123-lchild&!T123-rchild)return 1;else return LeafNum(T123-lchild)+LeafNum(T123-rchild); 11int main()int num123;struct BiTree* T123;printf(请输入二叉树的元素:n);T123=CreatBiTree(); /创建二叉树while(T123=NULL)printf(empoty,again:n);T123=CreatBiTre

12、e(); num123=LeafNum(T123);printf(二叉树叶子结点数目位:%dn,num123);return 0; 运行结果如下:12实验项目:图的应用实验学时: 2实验日期:实验要求:熟悉并掌握图的构造算法的使用实验内容:有向图的邻接表存储程序代码如下:#includeconst int MAX_SIZE=20;typedef struct ArcNodeint adjvex123;int value123;struct ArcNode* nextarc123;typedef struct VNodeint data123;/ArcNode *firstarc;/邻接表表头指

13、针VNode,AdjListMAX_SIZE;typedef structAdjList vertices;/邻接表数组int vexnum123,arcnum123;/顶点数和边数ALGraph;void CreateALGraph(ALGraph &algraph) /创建图函数int i,head123,tail123,value123;ArcNode * p123,*q123;printf(输入顶点数:);scanf(%d,&algraph.vexnum123);printf(输入边数:);scanf(%d,&algraph.arcnum123);13/初始化图for(i=0;iadj

14、vex123=tail123;p-value123=value123;if(algraph.verticeshead123.firstarc123=NULL) /表头为空algraph.verticeshead123.firstarc123=p;p-nextarc123=NULL;else /表头非空 p-nextarc123=algraph.verticeshead123.firstarc123;algraph.verticeshead123.firstarc123=p123;/end for;void PrintALGraph(const ALGraph &algraph)/输出图for(int i=0;i%d,algraph.verticesi.data123,p-adjvex123,p-value123);p123=p123-nextarc123;/指向下个节点printf(nn);int main()ALGraph algraph1,algraph2;CreateALGr

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

当前位置:首页 > 行业资料 > 其它行业文档

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