热门

最新

红包

立Flag

投票

同城

我的

发布
m0_62551548
zhanzejian
3 年前
truem0_62551548

#include<iostream>
using namespace std;
#define MAXV<100>
const int MAX=100010;
#define INF 32767
typedef char InfoType;

//边
typedef struct ANode
{
int adjvex;
struct ANode* nextarc;
int weight;
}ArcNode;

typedef struct Vnode
{
InfoType info;
ArcNode* firstarc;//指向第一个边结点
}VNode;

typedef struct
{
VNode adjlist[MAX];//邻接表的头结点数组
int n, e;//图中顶点数n和边数e
}AdjGraph;

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
void CreateAdj(AdjGraph*& G, int A[7][7], int n, int e){ int i, j; ArcNode* p; G = (AdjGraph*)malloc(sizeof(AdjGraph)); for (int i = 0; i < n; i++) G->adjlist[i].firstarc = NULL; for (i = 0; i < n; i++) { for (j = n - 1; j >= 0; j--) { if (A[i][j] != 0 && A[i][j] != INF) { p = (ArcNode*)malloc(sizeof(ArcNode)); p->adjvex = j;//存放邻接点 p->weight = A[i][j];//存放权 p->nextarc = G->adjlist[i].firstarc; G->adjlist[i].firstarc = p; } } } G->n = n; G->e = e;}void DispAdj(AdjGraph* G){ int i; ArcNode* p; for (i = 0; i < G->n; i++) { p = G->adjlist[i].firstarc; printf("%3d:", i); while (p != NULL) { printf("%3d[%d]->", p->adjvex, p->weight); p = p->nextarc; } printf("\n"); }}
立即登录