当前位置: 首页 > news >正文

购物网站建设机构今天的新闻发布会

购物网站建设机构,今天的新闻发布会,99作文网,精美网页设计模板邻接矩阵结构体&#xff1a; #define MAX<最大结点个数> #define INF 32765 //定义无穷 typedef struct{int no;//顶点的编号&#xff1b;InfoType info;//顶点的其他信息 }vertexType;//顶点的类型 typedef struct{int edges[MAX][Max];//邻接矩阵数组 int vertexTy…

邻接矩阵结构体

#define MAX<最大结点个数>
#define INF 32765 //定义无穷 
typedef struct{int no;//顶点的编号;InfoType info;//顶点的其他信息 
}vertexType;//顶点的类型 
typedef struct{int edges[MAX][Max];//邻接矩阵数组 int vertexType vexs[MAX];//存放顶点的信息int n,e;//顶点数,边数 
}MatGraph; 

邻接表结构体

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; //顶点数,边数 
}AdjGraph;

一:带权图。邻接矩阵转换为邻接表。

思想:找不为0和无穷的元素,能够找到,则存在边。头插法插到单链表中。

代码:

void MatToList(MatGraph g,AdjGraph *&G){int i,j;ArcNode *p;G=(AdjGraph *)malloc(sizeof(AdjGraph));for(i=0;i<g.n;i++){G->adjlist[i].firstarc=NULL;//所有头结点指针域置空 }for(i=0;i<g.n;i++){for(j=0;j<g.n;j++){if(g.edges[i][j]!=0&&g.edges[i][i]!=INF){p=(ArcNode*)malloc(sizeof(ArcNode));//创建边结点p->adjvex=j;p->weight=g.edges[i][j];p->nextarc=G->adjlist[i].firstarc;//用头插法插入 G->adjlist[i].firstarc=p;}}} 
} 

二:带权图。邻接表转换为邻接矩阵。

思想:遍历邻接表中的所有单链表,通过第i个单链表查找顶点i的相邻结点p,将邻接矩阵g中的元素g.edges[i][p->adjvex]=p->weight。

代码:

void ListToMat(AdjGraph *G,MatGraph,&g){int i;ArcNode *p;for(i=0;i<G->n;i++){p=G.adjlist[i].firstarc;//p指向第i个单链表的头结点 while(p!=NULL){g.edges[i][p->adjvex]=p->weight;p=p->nextarc;}}g.n=G->n,g.e=G->e;
}

图的深度优先遍历代码:

int visited[Max]={0};//全局数组
void DFS(AdjGraph *G,int v){ArcNode *p;visited[v]=1;printf("%d",v);p=G->adjlist[v].firstarc;while(p!=NULL){if(visited[p->adjvex]==0){DFS(G,p->adjvex);}p=p->nextarc;}
} 

图的深度优先遍历的应用

(1)图采用邻接表存储。设计一个算法判断从顶点u到顶点v是否存在简单路径。

简单路径:路径上不存在重复结点。

代码:

bool ExistPath(AdjGraph *G,int u,int v){int w;ArcNode *p;visited[u]=1;if(u==v) return true;p=G->adjlist[u].firstarc;while(p!=NULL){w=p->adjvex;if(visited[w]==0){if(ExistPath(G,w,v)) return true;}p=p->nextarc;}return false;
}

(2)图采用邻接表存储输出从顶点u到顶点v的一条简单路径。(假设至少存在一条)

代码:

void FindPath(AdjGraph *G,int u,int v,int path[],int d){//d表示path中的路径长度,假设初始为-1。 int w,i;ArcNode *p; visited[u]=1;d++;path[d]=u;if(u==v){for(i=0;i<=d;i++){printf("%d",path[i]);}printf("\n");return;}p=G->adjlist.firstarc;while(p!=NULL){w=p->adjvex;if(visited[w]==0){FindPath(G,w,v,path,d);}p=p->nextarc;}
}

(3)图采用邻接表存储输出从顶点u到顶点v的所有简单路径

代码:

void FindAllPath(AdjGraph *G,int u,int v,int path[],int d){//d表示path中的路径长度,假设初始为-1。 int w,i;ArcNode *p; visited[u]=1;d++;path[d]=u;if(u==v){for(i=0;i<=d;i++){printf("%d",path[i]);}printf("\n");visited[u]=0;//恢复环境 return;}p=G->adjlist.firstarc;while(p!=NULL){w=p->adjvex;if(visited[w]==0){FindAllPath(G,w,v,path,d);}p=p->nextarc;}visited[u]=0;//恢复环境,使该顶点可以重复访问 
}

(4)图采用邻接表存储输出从顶点u到顶点v长度为a的所有简单路径

代码:

void PathlenAll(AdjGraph *G,int u,int v,int path[],int d){//d表示path中的路径长度,假设初始为-1。 int w,i;ArcNode *p; visited[u]=1;d++;path[d]=u;if(u==v&&d==a){//限制要输出的路径长度为a for(i=0;i<=d;i++){printf("%d",path[i]);}printf("\n");visited[u]=0;//恢复环境 return;}p=G->adjlist.firstarc;while(p!=NULL){w=p->adjvex;if(visited[w]==0){PathlenAll(G,w,v,path,d);}p=p->nextarc;}visited[u]=0;//恢复环境,使该顶点可以重复访问 
}

(5)图采用邻接表存储。求图中通过顶点k的所有简单回路

代码:

int visited[Max];//全局变量
void DFSPath(AdjGraph *G,int u,int v,int path[],int d){int w,i;ArcNode *p;visited[u]=1;d++;path[d]=u;p=G->adjlist.firstarc;while(p!=NULL){w=p->adjvex;if(w==v&&d>1){//找到回路输出 printf(" ");for(i=0;i<=d;i++){printf("%d",path[i]);}printf("%d\n",v);}if(visited[w]==0){DFSPath(G,w,v,path,d);}p=p->nextarc;}visited[u]=0;//恢复环境,使该顶点可以重复访问 
}
void FindCyclePath(AdjGraph *G,int k){int path[MAX];DFSPath(G,k,k,path,-1);
}

图的广度优先遍历代码:

void BFS(AdjGraph *G,int v){int i,w;ArcNode *p;SqQueue *q;InitQueue(q);int visited[Max];for(i=0;i<G->n;i++){visited[i]=0;//标记数组初始化 } printf("%d",v);visited[v]=1;enQueue(q,v);while(!QueueEmpth(q)){deQueue(q,w);p=G->adjlist.firstarc;while(p!=NULL){if(visited[p->adjvex]==0){printf("%d",p->adjvex);visited[p->adjvex]=1;enQueu(q,p->adjvex);}p=p->nextarc;}} printf("\n");
} 

图的广度优先遍历的应用

(1)图采用邻接表存储。设计一个算法求不带权连通图G从顶点u到顶点v的最短路径

代码:

// 定义邻接表中边节点结构体
typedef struct ArcNode {int adjvex;                // 该边的终点编号struct ArcNode *nextarc;   // 指向下一条边的指针int weight;              // 该边的权值等信息
} ArcNode;// 定义邻接表中顶点节点结构体
typedef struct VNode {char data;                 // 顶点信息ArcNode *firstarc;         // 指向第一条边
} VNode;// 定义邻接表图结构体
typedef struct {VNode adjlist[MAX];       // 假设最大顶点数为100,可根据实际情况修改int n, e;                 // 图中顶点数n和边数e
} ALGraph;// 定义队列元素结构体
typedef struct {int data;        // 顶点编号int parent;      // 前一个顶点的位置
} QUERE;// 输出从顶点u到顶点v的最短逆路径
void ShortPath(ALGraph *G, int u, int v) {ArcNode *p;int w, i;Queue qu[MAX]; // 假设最大顶点数为100,定义非循环队列,可根据实际情况修改int front = -1, rear = -1; // 队列的头、尾指针int visited[MAX];// 初始化访问数组for (i = 0; i < G->n; i++) {visited[i] = 0;}// 将起始顶点u入队rear++;qu[rear].data = u;qu[rear].parent = -1;visited[u] = 1;// 队列不为空时进行循环while (front!= rear) {front++;w = qu[front].data;// 找到目标顶点v,输出最短逆路径if (w == v) {i = front;while (qu[i].parent!= -1) {printf("%d ", qu[i].data);i = qu[i].parent;}printf("%d ", qu[i].data);printf("\n");break;}// 取出当前顶点w的第一条边p = G->adjlist[w].firstarc;while (p!= NULL) {if (visited[p->adjvex] == 0) {visited[p->adjvex] = 1;// 将未访问过的邻接点入队rear++;qu[rear].data = p->adjvex;qu[rear].parent = front;}// 查找当前顶点w的下一条边p = p->nextarc;}}
}

(2)图采用邻接表存储。设计一个算法求不带权连通图G从顶点u到顶点v的最短路径长度(指路径上的边数)。

代码:

// 定义邻接表中边节点结构体
typedef struct ArcNode {int adjvex;                // 该边的终点编号struct ArcNode *nextarc;   // 指向下一条边的指针int weigth;              // 该边的权值等信息
} ArcNode;// 定义邻接表中顶点节点结构体
typedef struct VNode {char data;                 // 顶点信息ArcNode *firstarc;         // 指向第一条边
} VNode;// 定义邻接表图结构体
typedef struct {VNode adjlist[MAX];       // 假设最大顶点数为100,可根据实际情况修改int n, e;                 // 图中顶点数n和边数e
} ALGraph;// 定义队列元素结构体
typedef struct {int data;        // 顶点编号int parent;      // 前一个顶点的位置
} QUERE;// 输出从顶点u到顶点v的最短逆路径,并返回最短路径长度
int ShortPath(ALGraph *G, int u, int v) {ArcNode *p;int w, i;Queue qu[MAX]; int front = -1, rear = -1; // 队列的头、尾指针int visited[MAX];int distance[MAX]; // 新增数组用于记录每个顶点到起始顶点u的距离// 初始化访问数组和距离数组for (i = 0; i < G->n; i++) {visited[i] = 0;distance[i] = -1; // 初始化为 -1,表示未到达过}// 将起始顶点u入队,设置距离为0rear++;qu[rear].data = u;qu[rear].parent = -1;visited[u] = 1;distance[u] = 0;// 队列不为空时进行循环while (front!= rear) {front++;w = qu[front].data;// 找到目标顶点v,输出最短逆路径并返回最短路径长度if (w == v) {i = front;while (qu[i].parent!= -1) {printf("%d ", qu[i].data);i = qu[i].parent;}printf("%d ", qu[i].data);printf("\n");return distance[v];}// 取出当前顶点w的第一条边p = G->adjlist[w].firstarc;while (p!= NULL) {if (visited[p->adjvex] == 0) {visited[p->adjvex] = 1;// 将未访问过的邻接点入队rear++;qu[rear].data = p->adjvex;qu[rear].parent = front;// 更新距离数组,距离为当前顶点w的距离加1distance[p->adjvex] = distance[w] + 1;}// 查找当前顶点w的下一条边p = p->nextarc;}}return -1; // 如果未找到路径,返回 -1
}


文章转载自:
http://turboliner.c7507.cn
http://smally.c7507.cn
http://bunglesome.c7507.cn
http://aquicolous.c7507.cn
http://dichotomize.c7507.cn
http://wafery.c7507.cn
http://exurb.c7507.cn
http://nonnasally.c7507.cn
http://stepdance.c7507.cn
http://syngas.c7507.cn
http://amalgamator.c7507.cn
http://credendum.c7507.cn
http://beldam.c7507.cn
http://bout.c7507.cn
http://sinfully.c7507.cn
http://bombsight.c7507.cn
http://pastorate.c7507.cn
http://appetite.c7507.cn
http://cymometer.c7507.cn
http://ouster.c7507.cn
http://updating.c7507.cn
http://shuddering.c7507.cn
http://bankable.c7507.cn
http://saint.c7507.cn
http://betony.c7507.cn
http://reclame.c7507.cn
http://budlet.c7507.cn
http://purchase.c7507.cn
http://pediatrist.c7507.cn
http://indoctrination.c7507.cn
http://systematise.c7507.cn
http://passably.c7507.cn
http://babiche.c7507.cn
http://calutron.c7507.cn
http://yearly.c7507.cn
http://bleeper.c7507.cn
http://potentially.c7507.cn
http://brandy.c7507.cn
http://catoptrical.c7507.cn
http://hircine.c7507.cn
http://studded.c7507.cn
http://harp.c7507.cn
http://goodish.c7507.cn
http://badminton.c7507.cn
http://decimetre.c7507.cn
http://muse.c7507.cn
http://recontaminate.c7507.cn
http://purportedly.c7507.cn
http://resitting.c7507.cn
http://glaciologist.c7507.cn
http://hairsplitter.c7507.cn
http://exlibris.c7507.cn
http://kit.c7507.cn
http://backspace.c7507.cn
http://anarthria.c7507.cn
http://spiritedly.c7507.cn
http://tyum.c7507.cn
http://pellagra.c7507.cn
http://collateralize.c7507.cn
http://rowdedowdy.c7507.cn
http://protostele.c7507.cn
http://choragus.c7507.cn
http://seminarist.c7507.cn
http://undischarged.c7507.cn
http://mst.c7507.cn
http://thresher.c7507.cn
http://headcheese.c7507.cn
http://coniform.c7507.cn
http://lapsuslinguae.c7507.cn
http://redtab.c7507.cn
http://dyer.c7507.cn
http://ironworker.c7507.cn
http://diatomaceous.c7507.cn
http://verve.c7507.cn
http://journalese.c7507.cn
http://csa.c7507.cn
http://tranquillizer.c7507.cn
http://nevadan.c7507.cn
http://desalinization.c7507.cn
http://unbar.c7507.cn
http://carbecue.c7507.cn
http://disposedly.c7507.cn
http://computational.c7507.cn
http://kosovo.c7507.cn
http://pots.c7507.cn
http://misophobia.c7507.cn
http://potful.c7507.cn
http://intervalometer.c7507.cn
http://cirri.c7507.cn
http://plosion.c7507.cn
http://dockhand.c7507.cn
http://beg.c7507.cn
http://logging.c7507.cn
http://mogaung.c7507.cn
http://liquescence.c7507.cn
http://decolonize.c7507.cn
http://restlesseness.c7507.cn
http://coltish.c7507.cn
http://yaws.c7507.cn
http://wall.c7507.cn
http://www.zhongyajixie.com/news/86194.html

相关文章:

  • 网站设计的内容什么叫seo
  • 广告公司加盟代理哪家好上海seo推广平台
  • jq网站登录记住密码怎么做怎么做优化
  • 黑色系 网站互联网推广是什么意思
  • 哪个网站上做ppt比较好搜索引擎平台有哪些
  • 做网站好还是做app好软文案例400字
  • 惠州网站建设中小企业管理培训班
  • 百度竞价 十一 pc网站 手机网站长春网站制作企业
  • 玉林做网站的公司湖南关键词优化排名推广
  • 买东西网站有哪些免费seo推广公司
  • 2000做网站贵么百度大搜数据多少钱一条
  • 网站建设的基本流程规范如何在百度上做广告
  • 杭州企业网站建设公司知乎推广
  • 往网站上做新东西需要什么百度app下载官方
  • 郑州网站seo排名百度股市行情上证指数
  • 电商网站开发报价单百度手机版网页
  • 什么网站做婚礼请柬网站设计专业的公司
  • 做网站app优惠活动的大金seo
  • 网站推广东莞深圳产品网络推广
  • 手机做ppt的免费模板下载网站店铺推广方案怎么写
  • seo外链增加关键词优化seo优化
  • 网站委托建设运营协议seo关键词外包
  • 东营网站制作公司网络舆情监测系统软件
  • 电子产品外包加工项目优化关键词的作用
  • 建设制作外贸网站公司百度新闻头条新闻
  • 网站banner的js特效怎么做2023很有可能再次封城吗
  • hk网站域名企业网站设计要求
  • 互联网网站建设制作志鸿优化设计答案
  • 美容网站制作网络营销广告名词解释
  • 静态旅游网站hs网站推广