哈工大计算机软件基础实验报告范例哈工大计算机软件基础实验报告范例
实验一 顺序存储的线性表维护子系统的实现
实验报告
姓名: 学号: 日期:
一、实验程序
#include
#define max 20
int last=20;
int node[max]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int main()
{
int i,a,x,c,p,flag=0,r,s,u,v;
int find(int x);
void insert(int p,in...
哈工大计算机软件基础实验
报告
软件系统测试报告下载sgs报告如何下载关于路面塌陷情况报告535n,sgs报告怎么下载竣工报告下载
范例
实验一 顺序存储的线性表维护子系统的实现
实验报告
姓名: 学号: 日期:
一、实验程序
#include
#define max 20
int last=20;
int node[max]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int main()
{
int i,a,x,c,p,flag=0,r,s,u,v;
int find(int x);
void insert(int p,int x);
void delet(int p);
void modify(int p,int x);
printf("please enter number:\n1,查找值为x的点\n2,删除下标为p的节点\n3,
修改下标为r的节点的值为s\n4,在下标为u的节点之前插入v\n5,退出系统\n");
do
{
scanf("%d",&a);
switch(a)
{
case 1:
printf("please enter the x\n");
scanf("%d",&x);
c=find(x);
printf("findresult=%d\n",c);
break;
case 2:
printf("please enter the delete pot p\n");
scanf("%d",&p);
printf("before delete\n");
for(i=0;i<=last-1;i++)
printf("%d ",node[i]);
printf("\n");
delet(p);
printf("after delete\n");
for(i=0;i<=last-1;i++)
printf("%d ",node[i]);
printf("\n");
break;
case 3:
printf("please enter the pot r and the value s\n");
scanf("%d %d",&r,&s);
printf("before modify\n");
for(i=0;i<=last-1;i++)
printf("%d ",node[i]);
printf("\n");
modify(r,s);
printf("after modify\n");
for(i=0;i<=last-1;i++)
printf("%d ",node[i]);
printf("\n");
break;
case 4:
printf("please enter the pot p and the value x\n");
scanf("%d %d",&u,&v);
printf("before insert\n");
for(i=0;i<=last-1;i++)
printf("%d ",node[i]);
printf("\n");
insert(u,v);
printf("after insert\n");
for(i=0;i<=last-1;i++)
printf("%d ",node[i]);
printf("\n");
break;
case 5:
flag=1;
break;
default:
printf("input error\n");
}
}while(!flag);
return(0);
}
int find(int x)
{
int k,findi;
int flag2;
k=findi=flag2=0;
while(k<=last-1&&!flag2)
{
if(node[k]==x)
{
findi=k;
flag2=1;
}
else
k++;
}
if(!flag2)
findi=-1;
return(findi);
}
void delet(int p)
{
int j;
if(p>last-1||p<0)
printf("wrong position!\n");
else
{
for(j=p+1;j<=last-1;j++)
node[j-1]=node[j];
last=last-1;
}
}
void modify(int p,int x) {
node[p]=x;
}
void insert(int p,int x) {
int m;
if(last==max)
printf("the list is full!\n");
else
{
for(m=last-1;m>=p;m--)
node[m+1]=node[m];
node[p]=x;
last=last+1;
}
}
二、实验过程
根据题目要求,写出顺序存储的线性表的建立,查找,插入,删除,修改各段的子程序,
主函数由switch case 语句构成主菜单,再将各部分有机结合在一起,经过反复的运行调
试,得到最终的程序。
三、实验
分析
定性数据统计分析pdf销售业绩分析模板建筑结构震害分析销售进度分析表京东商城竞争战略分析
在线性表的建立时,我直接用数组赋给它初值;在查找功能中要实现,当能找到时返回该值,找不到返回-1;而修改功能则是在查找的基础上,将找到的值加以修改;在插入功能中要实现,再找到指定节点的基础上,当线性表满时,不能插入,当线性表不满时,可以插入;在删除功能重要实现,当线性表为空时或者删除位置不对时,都显示位置错误,不可删除,否则才可删除。
四、实验结论
1(查找
2.删除
3.修改
4.插入及退出
实验二 二叉树的前序遍历程序的实现
实验报告
姓名: 学号: 日期:
一、实验程序
#include
#include
#define max 22
struct node
{
int data;
struct node *llink;
struct node *rlink; }*shutree=NULL;
int main()
{
struct node *createtree(struct node *tree);
void preorder(struct node *t);
shutree=createtree(shutree);
preorder(shutree);
return(0);
}
void preorder(struct node *tree) {
struct node*p;
struct node*s[max];
int top;
top=-1;
p=tree;
do
{
while(p!=NULL)
{
printf(" %c",p->data);
if(p->rlink!=NULL)
{
top=top+1;
s[top]=p->rlink;
}
p=p->llink;
}
if(top!=-1)
{
p=s[top];
top=top-1;
}
}while(p!=NULL || top!=-1); }
struct node *createtree(struct node *tree)
{
char ch;
scanf("%c",&ch);
if(ch=='=')
tree=NULL;
else
{
tree=(struct node *)malloc(sizeof(struct node));
tree->data=ch;
createtree(tree->llink);
createtree(tree->rlink);
}
return(tree);
}
二、实验过程
先用递归算法建立一颗二叉树,当输入为#时,所对应的节点为空其余全都输入字母,然后再用非递归算法,前序遍历一颗二叉树:即按照访问根节点,遍历左子树,遍历右子树的顺序,遍历这颗二叉树。
三、实验分析
在二叉树的建立时,以所输入的字母为其数据项;遍历时,打印相应的节点值。 四、实验结论
实验三 二叉排序树维护子系统实现
实验报告
姓名: 学号: 日期:
一、实验程序
#include
#include
#include
#define max 9
int a[max];
struct node
{
int data;
struct node *llink;
struct node *rlink;
}*shutree=NULL,*j,*o,*h; int main()
{
int n,i,k,m,l,x,y,z;
int flag1=0;
struct node *find(struct node *tree,int x);
struct node *insertree(struct node *tree,int x);
struct node *detree(struct node *t,struct node *f,struct node *p);
void preorder(struct node *tree);
printf("input data\n");
for(i=0;i<9;i++)
scanf("%d",&a[i]);
printf("\n");
printf("请输入n\n");
printf("1 插入\n2 删除\n3 查找\n4 替换\n5 退出\n");
do
{
scanf("%d",&n);
printf("\n");
switch (n)
{
case 1:
for(i=0;i<9;i++)
shutree=insertree(shutree,a[i]);
printf("插入后\n");
preorder(shutree);
printf("\n");
break;
case 2:
printf("输入你要删除的值\n");
scanf("%d",&k);
j=find(shutree,k);
printf("输入你要删除结点的双亲值(无双亲输入0)\n");
scanf("%d",&l);
if(l==0)
{
h=NULL;
j=shutree;
}
else
h=find(shutree,l);
shutree=detree(shutree,h,j);
printf("删除后\n");
preorder(shutree);
printf("\n");
break;
case 3:
printf("输入你要查找的值\n");
scanf("%d",&m);
o=(struct node *)find(shutree,m);
if(o==NULL)
printf("result=0\n");
else
printf("resuct=1\n");
break;
case 4:
printf("替换前\n");
preorder(shutree);
printf("\n");
printf("将值为x(x的双亲为z)的结点替换为y\n");
scanf("%d %d %d",&x,&z,&y);
j=find(shutree,x);
if(z==0)
{
h=NULL;
j=shutree;
}
else
h=find(shutree,z);
shutree=detree(shutree,h,j);
shutree=insertree(shutree,y);
printf("替换后\n");
preorder(shutree);
printf("\n");
break;
case 5:
flag1=1;
break;
default:
printf("input error\n");
}
}while(flag1!=1);
return 0;
}
struct node *find(struct node *tree,int x)
{
int f;
struct node *p,*q;
p=tree;
f=0;
while((!f)&&(p!=NULL))
{
if(p->data==x)
f=1;
else
if(xdata)
p=p->llink;
else
p=p->rlink;
}
if(f)
q=p;
else
q=NULL;
return(q);
}
struct node *insertree(struct node *tree,int x)
{
struct node *p,*q;
if(tree==NULL)
{
p=(struct node *)malloc(sizeof(struct node));
p->data=x;
p->rlink=NULL;
p->llink=NULL;
tree=p;
}
else
{
p=tree;
while(p!=NULL)
{
q=p;
if(xdata)
p=p->llink;
else
p=p->rlink;
}
p=(struct node *)malloc(sizeof(struct node));
p->data=x;
p->rlink=NULL;
p->llink=NULL;
if(xdata)
q->llink=p;
else
q->rlink=p;
}
return(tree);
}
struct node *detree(struct node *t,struct node *f,struct node *p)
{
struct node*q,*s;
int bol;
bol=0;
if((p->llink==NULL)||(p->rlink==NULL))
{
if(p->llink==NULL)
{
if(p==t)
t=p->rlink;
else
{
s=p->rlink;
bol=1;
}
}
else
{
if(p==t)
t=p->llink;
else
{
s=p->llink;
bol=1;
}
}
}
else
{
q=p;
s=q->rlink;
while(s->llink!=NULL)
{
q=s;
s=s->llink;
}
s->llink=p->llink;
if(q!=p)
{
q->llink=s->rlink;
s->rlink=p->rlink;
}
if(p==t)
t=s;
else
bol=1;
}
if(bol==1)
{
if(p==f->llink)
f->llink=s;
else
f->rlink=s;
}
free(p);
return(t);
}
void preorder(struct node*tree) {
struct node*p;
struct node*s[max];
int top;
top=-1;
p=tree;
do
{
while(p!=NULL)
{
printf(" %d",p->data);
if(p->rlink!=NULL)
{
top=top+1;
s[top]=p->rlink;
}
p=p->llink;
}
if(top!=-1)
{
p=s[top];
top=top-1;
}
}while(p!=NULL || top!=-1);
}
二、实验过程
根据题目要求,写出二叉排序树插入,查找,删除,替换的程序段,主函数由switch case 语句构成主菜单,再将各部分有机结合在一起,经过反复的运行调试,得到最终的程序。
三、实验分析
在建立一颗二叉排序树树时,反复调用插入函数知道整个二叉排序树建立好;在查找时,要实现若找到返回1,没找到返回0;在删除时,要充分考虑到被删除节点的各种情况:是否有左子女,是否有右子女,是否有双亲;在替换时,实质就是将一个节点删除,然后再插入一个新节点。
四、实验结论
1.插入和查找 2.删除
3(替换及退出
本文档为【哈工大计算机软件基础实验报告范例】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。