数据结构 — 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
#includeusing 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月06日 07时55分18秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
CodeForces - 97B Superset (思维/分治/构造)
2019-04-30
CodeForces - 675A Infinite Sequence(简单数论 细节)
2019-04-30
CodeForces - 1042B Vitamins (思维)
2019-04-30
ACM 2013 长沙区域赛 Alice's Print Service (二分 思维)
2019-04-30
ACM 2013 长沙区域赛 Collision (几何)
2019-04-30
CodeForces - 1064A Make a triangle! (简单模拟)
2019-04-30
51Nod - 1183 编辑距离 (dp)
2019-04-30
ACM 2014 鞍山区域赛 E - Hatsune Miku (dp)
2019-04-30
反向传播&梯度下降 的直观理解程序(numpy)
2019-04-30
ACM 2017 南宁区域赛 Rake it in(对抗搜索)
2019-04-30
CodeForces - 931B World Cup (思维 模拟)
2019-04-30
CodeForces - 996D Suit and Tie (暴力)
2019-04-30
ACM 2017 香港区域赛 E - Base Station Sites(二分)
2019-04-30
ACM 2018 青岛区域赛 J-Books (模拟)
2019-04-30
ACM 2016 沈阳区域赛 E - Counting Cliques (dfs)
2019-04-30
ACM 2017 北京区域赛 J-Pangu and Stones(区间dp)
2019-04-30
HDU - 5643 King's Game (约瑟夫环变式)
2019-04-30