数据结构 — 7.有向图的创建及出入度的计算
发布日期:2021-06-30 19:49:34 浏览次数:2 分类:技术文章

本文共 1413 字,大约阅读时间需要 4 分钟。

【样例输入】

3 3

a b c 

a b

a c

b c   

【样例输出】

a  0 2

b  1 1

c  2  0

#include
using namespace std; #define MAX_VERTICES 50 /* 顶点最大数 */ #define ElementType char /* 元素的数据类型 */ typedef struct node { ElementType vertex; struct node *next; }NodeType,*NodePointer; typedef struct { ElementType v; NodePointer next;}GPointer; GPointer graph[MAX_VERTICES]; int vertices; int edge;void CreateGraph(){ ElementType ch,ch2; NodePointer pnew, pnode; pnew = pnode = NULL; for(int i = 0; i
>graph[i].v; graph[i].next = NULL; } for(int i = 0; i < edge; i++){ cin>>ch>>ch2; pnew = new NodeType(); pnew->vertex = ch2; pnew->next = NULL; for(int j = 0; j
next != NULL){ pnode = pnode->next; } pnode->next = pnew; } } } } int outdegree(int n){ int outd = 0; NodePointer np = graph[n].next; while(graph[n].next != NULL){ if(np->next == NULL) { outd++; break; }else{ outd++; np = np->next; } } return outd;}int indegree(int n){ int ind = 0; for(int i = 0;i
vertex == graph[n].v){ ind++; break; } np = np->next; } } return ind;}int main(){ // cout<<"输入"<
>vertices>>edge; CreateGraph(); for(int i = 0; i

转载地址:https://lipenglin.blog.csdn.net/article/details/50035311 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:数据结构 — 图 之 拓扑排序 (AOV网)
下一篇:数据结构 — 图 之 MPT(最短路径 — dijkstra算法 )

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月06日 07时55分18秒