{"action":"opened","issue":{"url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/27","repository_url":"https://api.github.com/repos/17070047/CodeStructureCourse","labels_url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/27/comments","events_url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/27/events","html_url":"https://github.com/17070047/CodeStructureCourse/issues/27","id":384076000,"node_id":"MDU6SXNzdWUzODQwNzYwMDA=","number":27,"title":"武智鹏","user":{"login":"wzpdreamer","id":45123697,"node_id":"MDQ6VXNlcjQ1MTIzNjk3","avatar_url":"https://avatars0.githubusercontent.com/u/45123697?v=4","gravatar_id":"","url":"https://api.github.com/users/wzpdreamer","html_url":"https://github.com/wzpdreamer","followers_url":"https://api.github.com/users/wzpdreamer/followers","following_url":"https://api.github.com/users/wzpdreamer/following{/other_user}","gists_url":"https://api.github.com/users/wzpdreamer/gists{/gist_id}","starred_url":"https://api.github.com/users/wzpdreamer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wzpdreamer/subscriptions","organizations_url":"https://api.github.com/users/wzpdreamer/orgs","repos_url":"https://api.github.com/users/wzpdreamer/repos","events_url":"https://api.github.com/users/wzpdreamer/events{/privacy}","received_events_url":"https://api.github.com/users/wzpdreamer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-25T12:50:17Z","updated_at":"2018-11-25T12:50:17Z","closed_at":null,"author_association":"NONE","body":"```c\r\n#include\"stdio.h\"\r\n#include\"stdlib.h\"\r\n#define M 20\r\n\r\ntypedef struct node{\r\n\tint adjvex;\r\n\tstruct node *next;\r\n}edgenode;\r\ntypedef struct vnode{\r\n\tchar vertex;\r\n\tedgenode *firstedge;\r\n}vertexnode;\r\ntypedef struct{\r\n\tvertexnode adjlist[M];\r\n\tint n,e;\r\n}linkedgraph;\r\nint visited[M];\r\n\r\nvoid create(linkedgraph *g,int c)\r\n{\r\n\tint i,j,k;\r\n\tedgenode *s;\r\n\tscanf(\"%d%d\",&g->n,&g->e);\r\n\tgetchar();\r\n\tprintf(\"%d vertex \",g->n);\r\n\tprintf(\"%d edges\\n\",g->e);\r\n\tfor(i=0;i<g->n;i++)\r\n\t{\r\n\t\tscanf(\"%c\",&g->adjlist[i].vertex);\r\n\t\tg->adjlist[i].firstedge=NULL;\r\n\t}\r\n\tfor(k=0;k<g->e;k++)\r\n\t{\r\n\t\tscanf(\"%d%d\",&i,&j);\r\n\t\ts=(edgenode*)malloc(sizeof(edgenode));\r\n\t\ts->adjvex=j;\r\n\t\ts->next=g->adjlist[i].firstedge;\r\n\t\tg->adjlist[i].firstedge=s;\r\n\t\tif(c=0)\r\n\t\t{\r\n\t\t\ts=(edgenode*)malloc(sizeof(edgenode));\r\n\t\t    s->adjvex=i;\r\n\t\t    s->next=g->adjlist[j].firstedge;\r\n\t\t    g->adjlist[j].firstedge=s;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nvoid dfs(linkedgraph *g,int i)\r\n{\r\n\tedgenode *p;\r\n\tprintf(\"%c \",g->adjlist[i].vertex);\r\n\tvisited[i]=1;\r\n\tp=g->adjlist[i].firstedge;\r\n\twhile(p)\r\n\t{\r\n\t\tif(!visited[p->adjvex])\r\n\t\t\tdfs(g,p->adjvex);\r\n\t\tp=p->next;\r\n\t}\r\n}\r\nvoid dfstraverse(linkedgraph *g)\r\n{\r\n\tint i;\r\n\tfor(i=0;i<g->n;i++)\r\n\t\tvisited[i]=0;\r\n\tfor(i=0;i<g->n;i++)\r\n\t\tif(!visited[i])\r\n\t\t\tdfs(g,i);\r\n\tprintf(\"\\n\");\r\n}\r\nvoid bfs(linkedgraph *g,int i)\r\n{\r\n\tint j;\r\n\tedgenode *p;\r\n\tint queue[M],front,rear;\r\n\tfront=rear=0;\r\n\tprintf(\"%c \",g->adjlist[i].vertex);\r\n\tvisited[i]=1;\r\n\tqueue[rear++]=i;\r\n\twhile(rear>front)\r\n\t{\r\n\t\tj=queue[front++];\r\n\t\tp=g->adjlist[j].firstedge;\r\n\t\twhile(p)\r\n\t\t{\r\n\t\t\tif(visited[p->adjvex]==0)\r\n\t\t\t{\r\n\t\t\t\tprintf(\"%c \",g->adjlist[p->adjvex].vertex);\r\n\t\t\t\tqueue[rear++]=p->adjvex;\r\n\t\t\t\tvisited[p->adjvex]=1;\r\n\t\t\t}\r\n\t\t\tp=p->next;\r\n\t\t}\r\n\t}\r\n}\r\nint bfstraverse(linkedgraph *g)\r\n{\r\n\tint i,count=0;\r\n\tfor(i=0;i<g->n;i++)\r\n\t\tvisited[i]=0;\r\n\tfor(i=0;i<g->n;i++)\r\n\t\tif(!visited[i])\r\n\t\t{\r\n\t\t\tcount++;\r\n\t\t\tbfs(g,i);\r\n\t\t}\r\n\treturn count;\r\n}\r\n\r\nint main()\r\n{\r\n\tlinkedgraph b;\r\n\tint count;\r\n\tcreate(&b,0);\r\n\tdfstraverse(&b);\r\n\tcount=bfstraverse(&b);\r\n\tprintf(\"该图共有%d个连通分量。\\n\",count);\r\n\treturn 0;\r\n}\r\n\r\n![1](https://user-images.githubusercontent.com/45123697/48979293-94dc8800-f0f3-11e8-83d3-e0189db2c3a9.png)\r\n\r\n\r\n```"}}
{"actor":{"display_login":"wzpdreamer"}}