电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

[数据结构]图的存储和遍历实验报告VIP免费

[数据结构]图的存储和遍历实验报告_第1页
1/8
[数据结构]图的存储和遍历实验报告_第2页
2/8
[数据结构]图的存储和遍历实验报告_第3页
3/8
《数据结构 B 》实验报告 系 计算机与电子 专业 级 0 1 _ _ 班 姓名学号2 0 1 0 年1 0 月 9 日 1. 上机题目: 图的存储和遍历 2. 详细设计 #include #define GRAPHMAX 10 #define FALSE 0 #define TRUE 1 #define error printf #define QueueSize 30 typedef struct { char vexs[GRAPHMAX]; int edges[GRAPHMAX][GRAPHMAX]; int n,e; }MGraph; int visited[10]; typedef struct { int front,rear,count; int data[QueueSize]; }CirQueue; void InitQueue(CirQueue *Q) { Q->front=Q->rear=0; Q->count=0; } int QueueEmpty(CirQueue *Q) { return Q->count=QueueSize; } int QueueFull(CirQueue *Q) { return Q->count==QueueSize; } void EnQueue(CirQueue *Q,int x) { if(QueueFull(Q)) error("Queue overflow"); else { Q->count++; Q->data[Q->rear]=x; Q->rear=(Q->rear+1)%QueueSize; } } int DeQueue(CirQueue *Q) { int temp; if(QueueEmpty(Q)) { error("Queue underflow"); return NULL; } else { temp=Q->data[Q->front]; Q->count--; Q->front=(Q->front+1)%QueueSize; return temp; } } void CreateMGraph(MGraph *G) { int i,j,k; char ch1,ch2; printf("\n\t\t 请输入定点数,边数并按回车(格式如:3,4):"); scanf("%d,%d",&(G->n),&(G->e)); for(i=0;in;i++) { getchar(); printf("\n\t\t 请输入第%d 个定点数并按回车:",i+1); scanf("%c",&(G->vexs[i])); } for(i=0;in;i++) for(j=0;jn;j++) G->edges[i][j]=0; for(k=0;ke;k++) { getchar(); printf("\n\t\t 请输入第%d 条边的顶点序号(格式如:i,j):",k+1); scanf("%c,%c",&ch1,&ch2); for(i=0;ch1!=G->vexs[i];i++); for(j=0;ch2!=G->vexs[j];j++); G->edges[i][j]=1; } } void DFSM(MGraph *G,int i) { int j; printf("\n\t\t 深度优先遍历序列: %c\n",G->vexs[i]); visited[i]=TRUE; for(j=0;jn;j++) if(G->edges[i][j]==1 && visited[j]!=1) //////////////// DFSM(G,j); } void BFSM(MGraph *G,int k) { int i,j; CirQueue Q; InitQueue(&Q); printf("\n\t\t 广度优先遍历序列:%c\n",G->vexs[k]); visited[k]=TRUE; EnQueue(&Q,k);...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

[数据结构]图的存储和遍历实验报告

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部