C语言邻接矩阵图创建和输出代码修复 - 完整示例
{///'title///': ///'C语言邻接矩阵图创建和输出代码修复 - 完整示例///', ///'description///': ///'修复C语言中使用邻接矩阵创建和输出图的代码错误,包括指针分配、字符串处理和数据类型匹配问题,并提供详细修复步骤和完整代码示例。///', ///'keywords///': ///'C语言, 邻接矩阵, 图, 数据结构, 代码修复, 字符串处理, 指针, 代码示例///', ///'content///': ///'#include<stdio.h>//n#include<string.h>//n#define maxv 10//n#define inf 32767//ntypedef char infotype;//ntypedef struct {//n int no;//n infotype *info;//n} vertextype;//ntypedef struct {//n int edges[maxv][maxv];//n vertextype vexs[maxv];//n int n;//n} matgraph;//n//nvoid creatematgraph(matgraph *&T, int n) {//n T = new matgraph;//n infotype ch[10];//n int k = 0, i = 0, j = 0;//n bool r;//n while (k < n) {//n scanf(///'%s///', ch);//n T->vexs[k].no = k;//n T->vexs[k].info = new infotype[strlen(ch) + 1];//n strcpy(T->vexs[k].info, ch);//n k++;//n }//n while (i < n) {//n j = 0;//n while (j < n) {//n printf(///'Is the edge [%d][%d] exist?//n///', i, j);//n scanf(///'%d///', &r);//n T->edges[i][j] = r;//n j++;//n }//n i++;//n }//n}//n//nvoid printgraph(matgraph &T, int n) {//n int k = 0;//n while (k < n) {//n printf(///'No%d:%s//n///', T->vexs[k].no, T->vexs[k].info);//n k++;//n }//n int i = 0, j = 0;//n while (i < n) {//n j = 0;//n while (j < n) {//n printf(///'%d//t///', T->edges[i][j]);//n j++;//n }//n printf(///'//n///', );//n i++;//n }//n}//n//nint main() {//n matgraph L;//n int n = 4;//n creatematgraph(&L, n);//n printgraph(&L, n);//n return 0;//n}//n///
原文地址: https://www.cveoy.top/t/topic/qfZU 著作权归作者所有。请勿转载和采集!