中国矿业大学测绘软件实习报告Word文档格式.docx

上传人:b****1 文档编号:1186912 上传时间:2023-04-30 格式:DOCX 页数:44 大小:179.75KB
下载 相关 举报
中国矿业大学测绘软件实习报告Word文档格式.docx_第1页
第1页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第2页
第2页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第3页
第3页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第4页
第4页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第5页
第5页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第6页
第6页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第7页
第7页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第8页
第8页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第9页
第9页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第10页
第10页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第11页
第11页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第12页
第12页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第13页
第13页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第14页
第14页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第15页
第15页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第16页
第16页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第17页
第17页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第18页
第18页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第19页
第19页 / 共44页
中国矿业大学测绘软件实习报告Word文档格式.docx_第20页
第20页 / 共44页
亲,该文档总共44页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

中国矿业大学测绘软件实习报告Word文档格式.docx

《中国矿业大学测绘软件实习报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《中国矿业大学测绘软件实习报告Word文档格式.docx(44页珍藏版)》请在冰点文库上搜索。

中国矿业大学测绘软件实习报告Word文档格式.docx

>

ch;

if(ch=='

#'

{

NO_Die=true;

//若为#,代表空节点

}

else

this->

data=ch;

//保存输入的节点

//左子树

C_LJH_BinTree*newChild0=newC_LJH_BinTree<

();

if(newChild0->

NO_Die)

deletenewChild0;

else

lchild=newChild0;

//右子树

C_LJH_BinTree*newChild1=newC_LJH_BinTree<

//直接创建子节点,

if(newChild1->

deletenewChild1;

rchild=newChild1;

}

//析构函数

~C_LJH_BinTree()

if(lchild)deletelchild;

//删除父节点之前,先删除子节点

if(rchild)deleterchild;

//前序遍历

voidC_LJH_BinTree<

PreOrder()

cout<

<

this->

data<

"

\t"

;

//先输出父节点,然后子节点按照父节点做

if(lchild!

=NULL)

this->

lchild->

PreOrder();

if(rchild!

rchild->

//中序遍历

InOrder()

if(lchild)lchild->

InOrder();

if(rchild)rchild->

//后序遍历

PostOrder()

PostOrder();

intmain()

请输入二叉树的前序遍历:

endl;

(以#作为分支结尾,例如:

AB##C##)"

C_LJH_BinTree<

char>

m_tree;

前序遍历为:

m_tree.PreOrder();

cout<

中序遍历为:

m_tree.InOrder();

后序遍历为:

m_tree.PostOrder();

return0;

实验结果:

实验体会:

通过本次试验,理解了二叉树类的构建、二叉树的建立及其遍历。

作为第一次实验,内容上实现实验所要求的目没有多大的难处,但其从数据结构出发,让我回忆起很多以前学过的知识,对我来说,收获不少。

实验二图的创建、遍历及其MST的构建

完成图的创建、遍历及最小数的构建,加深对图的认识以及对相关课本知识的认识。

1.图的创建。

2.基于深度优先的图的遍历算法的设计与实现。

3.基于广度优先的图的遍历算法的设计与实现。

4.基于Prim算法的最小生成树的构建。

5.基于Kruskal算法的最小生成树的构建。

structprimnode

{public:

charbegvex;

//开始结点

charendvex;

//结束结点

intlowcost;

//中间权值};

classLJH_Graphmtx//图的邻接矩阵定义

{public:

LJH_Graphmtx(intsz=DefaultVertices);

//构造函数

~LJH_Graphmtx()//析构函数

{delete[]VerticesList;

delete[]Edge;

}

boolGraphEmpty()//判断图是否为空

{if(numEdges==0)returntrue;

elsereturnfalse;

boolGraphFull()//判断图是否为满

{if(numVertices==maxVertices||numEdges==maxVertices*(maxVertices-1)/2)

returntrue;

returnfalse;

intNumberOfVertices()//返回当前顶点数

{returnnumVertices;

intNumberOfEdges()//返回当前边数

{returnnumEdges;

chargetValue(inti)//取顶点i的值,i不合理返回0

{returni>

=0&

&

i<

=numVertices?

VerticesList[i]:

NULL;

intgetWeight(intv1,intv2)//取边(v1,v2)上的权值

{returnv1!

=-1&

v2!

=-1?

Edge[v1][v2]:

0;

intgetFirstNeighbor(intv);

//取顶点v的第一个邻接顶点

intgetNextNeighbor(intv,intw);

//取v的邻接顶点w的下一邻接顶点

boolinsertVertex(charvertex);

//插入顶点vertex

boolinsertEdge(intv1,intv2,intweight);

//插入边(v1,v2),权为weight

boolremoveVertex(intv);

//删去顶点v和所有与它相关联的边

boolremoveEdge(intv1,intv2);

//在图中删去边(v1,v2)

intgetVertexPos(charvertex)//给出顶点vertex的位置,如果该顶点不在图内则返回-1

{for(inti=0;

numVertices;

i++)

if(VerticesList[i]==vertex)returni;

return-1;

intmini();

//求图中所有边的最小权值

boolinput();

//输入函数

booloutput();

//输出函数

voidkruskal();

//kruskal算法

voidprim();

//prim算法

protected:

intmaxVertices;

//图中最大顶点数

intnumEdges;

//图中当前边数

intnumVertices;

//图中当前顶点数

private:

char*VerticesList;

//顶点表

int**Edge;

//邻接矩阵

intvisit[50];

//便利时的辅助工具

primnodecloseedge[50];

//为实现prim函数的辅助结点};

LJH_Graphmtx:

LJH_Graphmtx(intsz)//构造函数

{maxVertices=sz;

numVertices=0;

numEdges=0;

inti,j;

VerticesList=newchar[maxVertices];

//创建顶点表数组

Edge=(int**)newint*[maxVertices];

//创建邻接矩阵数组

for(i=0;

maxVertices;

Edge[i]=newint[maxVertices];

for(i=0;

i++)//邻接矩阵初始化

for(j=0;

j<

j++)

Edge[i][j]=(i==j)?

0:

maxWeight;

intLJH_Graphmtx:

getFirstNeighbor(intv){if(v!

=-1)

if(Edge[v][i]>

0&

Edge[v][i]<

maxWeight)returni;

return-1;

getNextNeighbor(intv,intw)//给出顶点v的某邻接顶点w的下一个邻接顶点的位置,如果找不到,则函数返回-1

{if(v!

w!

{for(inti=w+1;

maxWeight)returni;

boolLJH_Graphmtx:

insertVertex(charvertex)//插入顶点vertex

{if(numVertices==maxVertices)returnfalse;

//顶点表满,不插入

VerticesList[numVertices++]=vertex;

returntrue;

insertEdge(intv1,intv2,intweight)//插入边(v1,v2),权为weight

{if(v1!

v1<

numVertices&

v2<

Edge[v1][v2]==maxWeight)////插入条件(?

?

{Edge[v1][v2]=Edge[v2][v1]=weight;

numEdges++;

returntrue;

else

returnfalse;

removeVertex(intv)//删去顶点v和所有与它相关联的边

{if(v<

v>

=numVertices)returnfalse;

//v不在图中,不删除

VerticesList[v]=VerticesList[numVertices-1];

//顶点表中删除该结点

i++)//减去与v相关联的边数

if(Edge[i][v]>

Edge[i][v]<

maxWeight)numEdges--;

i++)//用最后一列填补第v列

Edge[i][v]=Edge[i][numVertices-1];

numVertices--;

//顶点个数减1

for(j=0;

j++)//用最后一行填补第v行

Edge[v][j]=Edge[numVertices-1][j];

removeEdge(intv1,intv2)//在图中删去边(v1,v2)

{if(v1>

-1&

v2>

Edge[v1][v2]>

Edge[v1][v2]<

maxWeight)

{Edge[v1][v2]=Edge[v2][v1]=maxWeight;

//删除边(v1,v2)

numEdges--;

input()

{inti,j,k,n,m;

chare1,e2;

intweight;

请输入顶点数和边数:

cin>

n>

m;

//输入顶点数n和边数m

请输入顶点的值:

n;

i++)//依次输入顶点的值

{cin>

e1;

insertVertex(e1);

i=0;

while(i<

m)

{cout<

请输入端点信息:

e1>

e2>

weight;

//输入端点信息

j=this->

getVertexPos(e1);

//查顶点号

k=this->

getVertexPos(e2);

if(j==-1||k==-1)

边两端点信息输入有误,请重新输入!

else

{this->

insertEdge(j,k,weight);

i++;

}}

output()//输出函数

{inti,j,n,m;

intw;

n=this->

NumberOfVertices();

m=this->

NumberOfEdges();

顶点的个数为:

n<

边的条数为:

m<

所有边的信息为:

for(j=i+1;

{w=this->

getWeight(i,j);

if(w>

w<

{e1=this->

getValue(i);

e2=this->

getValue(j);

("

e1<

"

e2<

)"

}}

mini()//求图中所有边的最小权值,并返回

{staticinti;

intmin=0;

for(intj=0;

{if(!

visit[j])

{if(closeedge[min].lowcost>

closeedge[j].lowcost)

{min=j;

}}}

i=min;

cout<

包括边("

closeedge[i].begvex<

closeedge[i].endvex<

returni;

//图的深度优先搜索函数////////

voidDFS(LJH_Graphmtx&

G,intv,boolvisited[]);

//先声明函数,后使用

G,char&

v)//从顶点v出发,对图G进行深度优先遍历的主要过程

{inti,loc,n=G.NumberOfVertices();

//取图中顶点的个数

bool*visited=newbool[n];

//创建辅助数组

i++)//初始化辅助数组visited

{visited[i]=0;

loc=G.getVertexPos(v);

//取得v结点在图中的位置

DFS(G,loc,visited);

//从顶点0开始深度优先搜索

delete[]visited;

G,intv,boolvisited[])

{cout<

G.getValue(v)<

//访问顶点v

visited[v]=1;

//顶点v作访问标记

intw=G.getFirstNeighbor(v);

//找v的第一个邻接顶点w

while(w!

=-1)//若邻接顶点w存在

{if(visited[w]==0)

DFS(G,w,visited);

//若w未被访问,递归访问顶点w

w=G.getNextNeighbor(v,w);

//取v排在w后的下一个邻接顶点}}

//图的广度优先搜索函数////////

voidBFS(LJH_GraphmtxG,charv)//从顶点v出发,以广度优先的次序横向搜索图,算法中使用了一个队列。

{inti,w,n=G.NumberOfVertices();

//去图中的定点个数

bool*visited=newbool[n];

//用来记录顶点是否被访问过,被访问值为1,为被访问值为0

i++)//初始化

visited[i]=0;

intloc=G.getVertexPos(v);

//取顶点v的位置号

G.getValue(loc)<

visited[loc]=1;

//做已访问标记

LJH_QueueQ;

//定义一个辅助队列

Q.EnQueue(loc);

//顶点进队,实现分层访问

while(!

Q.IsEmpty())//循环访问所有结点,判断队列是否为空

{Q.DeQueue(loc);

//从队列中退出顶点loc

w=G.getFirstNeighbor(loc);

//找顶点loc的第一个邻接点w

while(w!

=-1)//若邻接点w存在

{if(visited[w]==false)//若未被访问

{cout<

G.getValue(w)<

//访问顶点w

visited[w]=1;

//标记w已经被访问

Q.EnQueue(w);

//顶点w进队列w=G.getNextNeighbor(loc,w);

//找顶点loc的下一个邻接顶点,重复检测v的所有邻接顶点}}

delete[]visited;

//////kruskal函数的实现//////

voidLJH_Graphmtx:

kruskal()

{inta,b,k=0;

intmin=maxWeight;

intEdge1[20][20];

for(intm=0;

m++)

visit[m]=m;

//每一个顶点属于一颗树

for(inti=0;

for(intj=0;

Edge1[i][j]=Edge[i][j];

while(k<

numVertices-1)

{min=maxWeight;

{for(intj=0;

{if(Edge1[i][j]<

min)

{a=i;

b=j;

min=Edge1[i][j];

}}}

if(visit[a]!

=visit[b])

VerticesList[a]<

VerticesList[b]<

k++;

for(intn=0;

n++)

{if(visit[n]==visit[b])visit[n]=visit[a];

}}

elseEdge1[a][b]=Edge[b][a]=maxWeight;

////////////Prim函数的实现////

prim()

{charu;

请输入起始顶点:

u;

inti=this->

getVertexPos(u);

visit[i]=1;

{closeedge[j].begvex=u;

closeedge[j].endvex=VerticesList[j];

closeedge[j].lowcost=Edge[i][j];

for(intm=1;

{intn=mini();

visit[n]=1;

closeedge[n].lowcost=maxWeight;

for(intp=0;

p<

p++)

visit[p])

{if(Edge[p][n]<

closeedge[p].lowcost)

{closeedge[p].lowcost=Edge[p][n];

closeedge[p].begvex=VerticesList[n];

}}}}}

经过这次实验让我更深刻的理解了类的创建及相互间调用,能够对二维数组的动态开辟空间和释放空间有了更深刻的理解,对图的遍历及构建最小生成树也有了深刻的体会。

总之,在这次试验中,学到了许多,也提高了自己的编程能力。

实验三、矩阵类的设计与实现

通过上机实践,实现矩阵的生成、加减乘除运算,以及求矩阵的转置、求逆和行列式。

同时加深对矩阵的理论的理解,并用计算机程序算法来描述矩阵生成及运算。

通过构造矩阵类,实现矩阵的定义,包括:

矩阵的加

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2