邻接表2 -试在邻接表存储结构上实现图的基本操作 del_vertex-数据结构-图-icoding

本文探讨如何在邻接表数据结构上实现图的基本操作——删除顶点del_vertex。文章指出判断条件和成功删除的标志,并提供了参考代码,同时对icoding的解决方案提出疑问,邀请读者在讨论区交流。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

邻接表2

试在邻接表存储结构上实现图的基本操作 del_vertex,相关定义如下:

typedef int VertexType;

typedef enum{
    DG, UDG
}GraphType;

typedef struct ArcNode{
    int adjvex;
    InfoPtr *info;
    struct ArcNode *nextarc;
}ArcNode;

typedef struct VNode{
    VertexType data;
    ArcNode *firstarc;
}VNode;
typedef struct{
    VNode vertex[MAX_VERTEX_NUM];
    int vexnum, arcnum;
    GraphType type;
}ListGraph;

int locate_vertex(ListGraph *G, VertexType v); //返回顶点 v 在vertex数组中的下标,如果v不存在,返回-1
bool del_vertex(ListGraph *G, VertexType v); //删除顶点 v

Attention: 判断条件如下:

当成功删除顶点或边时,函数返回true,否则(如顶点或边不存在、删除边时顶点v或w不存在)返回false。

参考代码如下:

//注意的一点是free函数包含在头文件<stdlib.h>中

#include <stdio.h>  
#include <stdlib.h>
#include "graph.h" //请勿删除,否则检查不通过
bool del_vertex(ListGraph* G, VertexType v)
{
    int i, j;
    ArcNode* p, *q;
    
	j = locate_vertex(G, v);
    if (j == -1) return false; 
    
    q = G->vertex[j].firstarc;
    i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风起风里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值