int DeleteVex(ALGragh &G) {//删除G中顶点f及其相关的弧 /**************begin************/ 补充完整
时间: 2023-12-06 14:02:43 浏览: 63
以下是删除图G中顶点v及其相关的弧的代码实现:
```c++
int DeleteVex(ALGraph &G, int v) {
// 删除顶点v及其相关的弧
ArcNode *p, *q;
int k = v;
for (int i = 0; i < G.vexnum; i++) {
p = G.vertices[i].firstarc;
while (p != NULL) {
if (p->adjvex == v) {
q = p;
p = p->nextarc;
free(q);
G.arcnum--;
} else {
p = p->nextarc;
}
}
}
p = G.vertices[v].firstarc;
while (p != NULL) {
q = p;
p = p->nextarc;
free(q);
G.arcnum--;
}
for (int i = v + 1; i < G.vexnum; i++) {
G.vertices[i - 1] = G.vertices[i];
}
G.vexnum--;
for (int i = 0; i < G.vexnum; i++) {
p = G.vertices[i].firstarc;
while (p != NULL) {
if (p->adjvex > k) {
p->adjvex--;
}
p = p->nextarc;
}
}
return OK;
}
```
阅读全文