{"record":{"id":"ed2ef07fde61dd45","repo":"krahets/hello-algo","slug":"error-ed2ef0","errorCode":null,"errorMessage":"圖的頂點數量已達最大值\n","messagePattern":"圖的頂點數量已達最大值\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"zh-hant/codes/c/chapter_graph/graph_adjacency_matrix.c","lineNumber":39,"sourceCode":"    GraphAdjMat *graph = (GraphAdjMat *)malloc(sizeof(GraphAdjMat));\n    graph->size = 0;\n    for (int i = 0; i < MAX_SIZE; i++) {\n        for (int j = 0; j < MAX_SIZE; j++) {\n            graph->adjMat[i][j] = 0;\n        }\n    }\n    return graph;\n}\n\n/* 析構函式 */\nvoid delGraphAdjMat(GraphAdjMat *graph) {\n    free(graph);\n}\n\n/* 新增頂點 */\nvoid addVertex(GraphAdjMat *graph, int val) {\n    if (graph->size == MAX_SIZE) {\n        fprintf(stderr, \"圖的頂點數量已達最大值\\n\");\n        return;\n    }\n    // 新增第 n 個頂點，並將第 n 行和列置零\n    int n = graph->size;\n    graph->vertices[n] = val;\n    for (int i = 0; i <= n; i++) {\n        graph->adjMat[n][i] = graph->adjMat[i][n] = 0;\n    }\n    graph->size++;\n}\n\n/* 刪除頂點 */\nvoid removeVertex(GraphAdjMat *graph, int index) {\n    if (index < 0 || index >= graph->size) {\n        fprintf(stderr, \"頂點索引越界\\n\");\n        return;\n    }\n    // 在頂點串列中移除索引 index 的頂點","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/zh-hant/codes/c/chapter_graph/graph_adjacency_matrix.c#L21-L57","documentation":"Traditional-Chinese (zh-hant) localization of the addVertex capacity check (see error 600). The graph's vertices[] and adjMat[][] are fixed at compile time via #define MAX_SIZE 100; the 101st addVertex logs to stderr and returns void without inserting.","triggerScenarios":"addVertex(graph, val) when graph->size == 100.","commonSituations":"Datasets larger than 100 nodes; stress tests past the cap; assuming dynamic resizing.","solutions":["Cap input at 100 vertices.","Raise MAX_SIZE and recompile (quadratic memory cost).","Use the adjacency-list implementation for larger graphs."],"exampleFix":"// before\nfor (int i = 0; i < 1000; i++) addVertex(graph, i);\n\n// after\nfor (int i = 0; i < 1000 && graph->size < MAX_SIZE; i++) addVertex(graph, i);","handlingStrategy":"validation","validationCode":"static inline int graphCanAddVertex(const GraphAdjMat *g) {\n    return g != NULL && g->size < MAX_SIZE;\n}\n\nif (graphCanAddVertex(graph)) addVertex(graph, val);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat MAX_SIZE (100) as a hard contract; assert before each addVertex in debug builds.","Choose the adjacency-list implementation for graphs that may exceed 100 nodes.","Wrap addVertex in a status-returning helper so failures surface beyond stderr."],"tags":["graph","capacity","adjacency-matrix","fixed-size","c","i18n-zh-hant"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}