From f1eeb54f944a21e0db67c13b686dc2b140e75aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E6=A5=A0?= <87896121@qq.com> Date: Sat, 8 Jul 2023 20:11:56 +0800 Subject: [PATCH 1/2] C3 --- xitong.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/xitong.c b/xitong.c index 8011a5f..714e489 100644 --- a/xitong.c +++ b/xitong.c @@ -37,4 +37,115 @@ fprintf(op,"%s\n",strs); } fclose(op); - } \ No newline at end of file + } + void creatnode() {//对节点进行初始化 + nm.e = 7;//边数 + nm.n = 7;//站点数 + FILE* op; + op=fopen(position,"rb"); + if(op==NULL) { + printf("文件不存在"); + } + int i=0; + while(1){ + char strs[100]; + if(fscanf(op,"%s",strs)!=EOF){ + //printf("%s\n",strs); + strcpy(nm.adjust[i].name,strs); + i++; + } + else break; + } + fclose(op); + for (i = 0; i < nm.n; i++) { + nm.adjust[i].firstnode = NULL; + } +} + +void printff(){ + for(int i=0;ia, "东安路"); + p->next = nm.adjust[0].firstnode; + nm.adjust[0].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "嘉善路"); + p->next = nm.adjust[0].firstnode; + nm.adjust[0].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "徐家汇"); + p->next = nm.adjust[0].firstnode; + nm.adjust[0].firstnode = p; + //下面是东安路的邻接表 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "肇嘉浜路"); + p->next = nm.adjust[1].firstnode; + nm.adjust[1].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育场"); + p->next = nm.adjust[1].firstnode; + nm.adjust[1].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "大木桥路"); + p->next = nm.adjust[1].firstnode; + nm.adjust[1].firstnode = p; + //下面是上海体育场的邻接表 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "东安路"); + p->next = nm.adjust[2].firstnode; + nm.adjust[2].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育馆"); + p->next = nm.adjust[2].firstnode; + nm.adjust[2].firstnode = p; + //下面是嘉善路的邻接表 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "大木桥路"); + p->next = nm.adjust[3].firstnode; + nm.adjust[3].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "肇嘉浜路"); + p->next = nm.adjust[3].firstnode; + nm.adjust[3].firstnode = p; + //下面是大木桥路 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "东安路"); + p->next = nm.adjust[4].firstnode; + nm.adjust[4].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "嘉善路"); + p->next = nm.adjust[4].firstnode; + nm.adjust[4].firstnode = p; + //下面是徐家汇 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "肇嘉浜路"); + p->next = nm.adjust[5].firstnode; + nm.adjust[5].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育馆"); + p->next = nm.adjust[5].firstnode; + nm.adjust[5].firstnode = p; + //下面是上海体育馆 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "徐家汇"); + p->next = nm.adjust[6].firstnode; + nm.adjust[6].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育场"); + p->next = nm.adjust[6].firstnode; + nm.adjust[6].firstnode = p; +} + int cont[100][100];//邻接矩阵 + void aaa(){ + int i,j; + for(i=0;i Date: Sat, 8 Jul 2023 20:16:23 +0800 Subject: [PATCH 2/2] C2 --- README.md | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5de2b8..a9205ff 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,117 @@ ``` ##C2:初始化节点以及打印节点名称并通过邻接表和邻接矩阵来表示图的结构{41-151} ``` -代码: +代码:void creatnode() {//对节点进行初始化 + nm.e = 7;//边数 + nm.n = 7;//站点数 + FILE* op; + op=fopen(position,"rb"); + if(op==NULL) { + printf("文件不存在"); + } + int i=0; + while(1){ + char strs[100]; + if(fscanf(op,"%s",strs)!=EOF){ + //printf("%s\n",strs); + strcpy(nm.adjust[i].name,strs); + i++; + } + else break; + } + fclose(op); + for (i = 0; i < nm.n; i++) { + nm.adjust[i].firstnode = NULL; + } +} + +void printff(){ + for(int i=0;ia, "东安路"); + p->next = nm.adjust[0].firstnode; + nm.adjust[0].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "嘉善路"); + p->next = nm.adjust[0].firstnode; + nm.adjust[0].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "徐家汇"); + p->next = nm.adjust[0].firstnode; + nm.adjust[0].firstnode = p; + //下面是东安路的邻接表 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "肇嘉浜路"); + p->next = nm.adjust[1].firstnode; + nm.adjust[1].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育场"); + p->next = nm.adjust[1].firstnode; + nm.adjust[1].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "大木桥路"); + p->next = nm.adjust[1].firstnode; + nm.adjust[1].firstnode = p; + //下面是上海体育场的邻接表 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "东安路"); + p->next = nm.adjust[2].firstnode; + nm.adjust[2].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育馆"); + p->next = nm.adjust[2].firstnode; + nm.adjust[2].firstnode = p; + //下面是嘉善路的邻接表 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "大木桥路"); + p->next = nm.adjust[3].firstnode; + nm.adjust[3].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "肇嘉浜路"); + p->next = nm.adjust[3].firstnode; + nm.adjust[3].firstnode = p; + //下面是大木桥路 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "东安路"); + p->next = nm.adjust[4].firstnode; + nm.adjust[4].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "嘉善路"); + p->next = nm.adjust[4].firstnode; + nm.adjust[4].firstnode = p; + //下面是徐家汇 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "肇嘉浜路"); + p->next = nm.adjust[5].firstnode; + nm.adjust[5].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育馆"); + p->next = nm.adjust[5].firstnode; + nm.adjust[5].firstnode = p; + //下面是上海体育馆 + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "徐家汇"); + p->next = nm.adjust[6].firstnode; + nm.adjust[6].firstnode = p; + p = (edgenode*)malloc(sizeof(edgenode)); + strcpy(p->a, "上海体育场"); + p->next = nm.adjust[6].firstnode; + nm.adjust[6].firstnode = p; +} + int cont[100][100];//邻接矩阵 + void aaa(){ + int i,j; + for(i=0;i