发布信息

实习题答案 严蔚敏数据结构题集 C言语版 (实训答案)

     2024-08-14 04:22:38     715

本文目录导航:

严蔚敏数据结构题集(C言语版)实习题答案

#include<stdio.h> #define MAXVEX 6 typedef char VexType; typedef float AdjType; typedef struct { int n; AdjType arcs[MAXVEX][MAXVEX]; } GraphMatrix; typedef struct{ int start_vex, stop_vex; AdjType weight; } Edge; Edge mst[5]; #define MAX 1e+8 void prim(GraphMatrix * pgraph, Edge mst[]) { int i, j, min, vx, vy; float weight, minweight; Edge edge; for (i = 0; i < pgraph->n-1; i++) { mst[i]_vex = 0; mst[i]_vex = i+1; mst[i] = pgraph->arcs[0][i+1]; } for (i = 0; i < pgraph->n-1; i++) { minweight = MAX; min = i; for (j = i; j < pgraph->n-1; j++) if(mst[j] < minweight) { minweight = mst[j]; min = j; } edge = mst[min]; mst[min] = mst[i]; mst[i] = edge; vx = mst[i]_vex; for(j = i+1; j < pgraph->n-1; j++) { vy=mst[j]_vex; weight = pgraph->arcs[vx][vy]; if (weight < mst[j]) { mst[j] = weight; mst[j]_vex = vx; } } } } GraphMatrix graph = { 6, {{0,10,MAX,MAX,19,21}, {10,0,5,6,MAX,11}, {MAX,5,0,6,MAX,MAX}, {MAX,6,6,0,18,14}, {19,MAX,MAX,18,0,33}, {21,11,MAX,14,33,0} } }; int main(){ int i; prim(&graph,mst); for (i = 0; i < graph.n-1; i++) printf((%d %d %.0f)\n, mst[i]_vex, mst[i]_vex, mst[i]); return 0; }

讨教一题数据结构(C言语),第5题

选B每个元素占1字节,那就是算[0][0]与[5][4]之间相差几个元素。设.[0][0]再内存中的地址为1那么,[5][4]再内存中地址等于1+2+3+4+5+5=20所以两者之差为19

一份C言语的数据结构标题,急求答案

第一题;Search (BiTree t,ElemType x){struct nodee;{BiTree pp;int tag;}s[100];int top; Bitree p;top=0; p=t;while(p!=NULL&&p->p!=NULL){while(p!=NULL&&p->data!=x){top++;s[top]=p;s[top]=0;p=p->lchild;}if(p!=NULL&&p->data==x){for(i=1; i<=top; i++)printf(s[i]->data);}elseif(top>0&&s[top]==1){top--;p=NULL;}elseif(top>0){s[top]=1;p=s[top];p=p->rchild;}}}

相关内容 查看全部