【数据结构与算法】分别以邻接矩阵和邻接表作为存储结构实现以下操作:1.增加一个新顶点v、2.删除顶点v及其相关的边、3.增加一条边<v,w>、4.删除一条边<v,w>

这篇具有很好参考价值的文章主要介绍了【数据结构与算法】分别以邻接矩阵和邻接表作为存储结构实现以下操作:1.增加一个新顶点v、2.删除顶点v及其相关的边、3.增加一条边<v,w>、4.删除一条边<v,w>。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

题目

  Qestion:分别以邻接矩阵和邻接表作为存储结构,实现以下图的基本操作

  1. 增加一个新顶点v,InsertVex(G, v)
  2. 删除顶点v及其相关的边,DeleteVex(G, v);
  3. 增加一条边<v,w>,InsertArc(G, v, w);
  4. 删除一条边<v,w>,DeleteArc(G, v, w)

该题所用的图结构

数据结构图增加顶点,算法与数据结构,C/C++,图论,c语言,链表,c++,矩阵


该题所用到的邻接表和邻接矩阵的图形表示

邻接表

数据结构图增加顶点,算法与数据结构,C/C++,图论,c语言,链表,c++,矩阵

邻接矩阵表示

数据结构图增加顶点,算法与数据结构,C/C++,图论,c语言,链表,c++,矩阵


数据结构与定义

因为要分别用邻接表和邻接矩阵来完成上述四个算法,故有两个数据结构的定义

邻接表数据结构定义

#include <stdio.h>
#include <iostream>

using namespace std;

#define MaxSize 20 // 最大顶点的个数
struct Node
{
    int weight;
    int index;
    struct Node *next;
};
struct HNode
{
    char nodeData;
    struct Node *next;
};
struct Graph
{
    int vertexNum;
    int arcNum;
    bool isDireted;
    HNode verList[MaxSize];
};

邻接矩阵数据结构定义

#include <stdio.h>
#include <iostream>

using namespace std;

#define Max 20
// 顶点信息
struct VertexItem
{
    char Vertex; // 顶点信息
    int index;   // 顶点在邻接矩阵中的下标
};
// 图的邻接矩阵存储
struct Graph
{
    int vertexNum;
    int arcNum;
    bool isDireted;
    int Matrix[Max][Max];
    VertexItem vertexList[Max]; // 顶点信息表
};

邻接表

增加一个新顶点v

void InsertVex(Graph &G, char v)
{
    G.verList[G.vertexNum].nodeData = v;
    G.verList[G.vertexNum].next = nullptr;
    G.vertexNum++;
}

删除顶点v及其相关的边

void DeleteVex(Graph &G, char v)
{
    int index = Locate(v, G); // 该顶点的下标
    // 释放与该顶点有关的所有边
    Node *p = G.verList[index].next; // 临时指针p指向该顶点邻接表的第一个结点
    while (p != nullptr)
    {
        if (!G.isDireted) // G为无向图
        {
            Node *q = G.verList[p->index].next; // 临时指针q指向待删除结点所在邻接表中的第一个结点
            while (q->next->index != index)     // 一直找,直到找到q的next结点的index值为删除顶点的index
            {
                q = q->next;
            }
            Node *needDel = q->next; // 创建一个临时指针,指向待删除的结点
            q->next = needDel->next; // 保证邻接表不断
            free(needDel);           // 释放空间
        }
        G.verList[index].next = p->next;
        G.arcNum--;
        free(p);
    }
    // 释放顶点
    G.verList[index].nodeData = NULL;
    G.verList[index].next = nullptr;
    G.vertexNum--;
    return;
}

增加一条边<v,w>

void InsertArc(Graph &G, char tail, char head)
{
    int TailIndex, HeadIndex;
    TailIndex = Locate(tail, G);
    HeadIndex = Locate(head, G);
    if (HeadIndex == -1 || TailIndex == -1) // 输入的弧头或者弧尾不存在
    {
        return;
    }
    // 无论G为有向图还是无向图
    Node *newNode = new Node;
    newNode->next = G.verList[TailIndex].next; // 头插法插入到邻接表中
    newNode->index = HeadIndex;
    G.verList[TailIndex].next = newNode;
    if (!G.isDireted) // G为无向图
    {
        Node *newNode = new Node;
        newNode->next = G.verList[HeadIndex].next; // 头插法插入到邻接表中
        newNode->index = TailIndex;
        G.verList[HeadIndex].next = newNode;
    }
}

删除一条边<v,w>

void DeleteArc(Graph &G, char tail, char head)
{
    int TailIndex = Locate(tail, G);
    int HeadIndex = Locate(head, G);
    Node *p = G.verList[TailIndex].next; // 临时指针p指向弧尾顶点邻接表的第一个结点
    while (p->next->index != HeadIndex)
    {
        p = p->next;
    }
    Node *needDel = p->next;
    p->next = needDel->next;
    free(needDel);
    G.arcNum--;
    if (!G.isDireted) // G为无向图
    {
        Node *q = G.verList[HeadIndex].next;
        while (q->next->index != TailIndex)
        {
            q = q->next;
        }
        needDel = q->next;
        q->next = needDel->next;
        free(needDel);
    }
}

邻接矩阵

增加一个新顶点v

// 添加顶点
void InsertVex(Graph &G, char c)
{
    G.vertexList[G.vertexNum].Vertex = c;          // 顶点信息存入顶点表中
    G.vertexList[G.vertexNum].index = G.vertexNum; // 顶点的在邻接矩阵的索引存入顶点表中                            // 顶点数量加一
    // 对新插入的顶点对应的矩阵初始化
    for (int i = 0; i <= G.vertexNum; i++)
    {
        G.Matrix[G.vertexNum][i] = 0;
        G.Matrix[i][G.vertexNum] = 0;
    }
    G.vertexNum++;
}

删除顶点v及其相关的边

// 删除顶点以及相关的边
void DeletVex(Graph &G, char c)
{
    int vexIndex = Locate(G, c);
    G.vertexNum--;
    for (int i = 0; i < G.vertexNum; i++)
    {
        if (G.Matrix[vexIndex][i] == 1) // 有边
        {
            G.Matrix[vexIndex][i] = 0;
            G.arcNum--;
        }
        if (G.Matrix[i][vexIndex] == 1)
        {
            G.Matrix[i][vexIndex] = 0;
        }
    }
    G.vertexList[vexIndex].index = -1;
}

增加一条边<v,w>

// 添加弧
void InsertArc(Graph &G, char tail, char head)
{
    int tailIndex = Locate(G, tail);
    int headIndex = Locate(G, head);
    if (headIndex == -1 || tailIndex == -1) // 输入的弧头或者弧尾不存在
    {
        return;
    }
    G.Matrix[tailIndex][headIndex] = 1;
    G.arcNum++;
    if (!G.isDireted)
    {
        G.Matrix[headIndex][tailIndex] = 1; // 若不是有向图则再添加一条对称边
    }
}

删除一条边<v,w>

// 删除弧
void DeleteArc(Graph &G, char tail, char head)
{
    int tailIndex = Locate(G, tail);
    int headIndex = Locate(G, head);
    if (headIndex == -1 || tailIndex == -1)
    {
        return;
    }
    G.Matrix[tailIndex][headIndex] = 0;
    G.arcNum--;
    if (!G.isDireted)
    {
        G.Matrix[headIndex][tailIndex] = 0; // 若不是有向图则再删除一条对称边
        G.arcNum--;
    }
}

完整代码

//这个是邻接表的完整代码
#include <stdio.h>
#include <iostream>

using namespace std;

#define MaxSize 20 // 最大顶点的个数
struct Node
{
    int weight;
    int index;
    struct Node *next;
};
struct HNode
{
    char nodeData;
    struct Node *next;
};
struct Graph
{
    int vertexNum;
    int arcNum;
    bool isDireted;
    HNode verList[MaxSize];
};

int Locate(char c, Graph G)
{
    int index = -1;
    for (int i = 0; i < G.vertexNum; i++)
    {
        if (G.verList[i].nodeData == c)
        {
            index = i;
        }
    }
    return index;
}

void InsertVex(Graph &G, char v)
{
    G.verList[G.vertexNum].nodeData = v;
    G.verList[G.vertexNum].next = nullptr;
    G.vertexNum++;
}

void InsertArc(Graph &G, char tail, char head)
{
    int TailIndex, HeadIndex;
    TailIndex = Locate(tail, G);
    HeadIndex = Locate(head, G);
    if (HeadIndex == -1 || TailIndex == -1) // 输入的弧头或者弧尾不存在
    {
        return;
    }
    // 无论G为有向图还是无向图
    Node *newNode = new Node;
    newNode->next = G.verList[TailIndex].next; // 头插法插入到邻接表中
    newNode->index = HeadIndex;
    G.verList[TailIndex].next = newNode;
    if (!G.isDireted) // G为无向图
    {
        Node *newNode = new Node;
        newNode->next = G.verList[HeadIndex].next; // 头插法插入到邻接表中
        newNode->index = TailIndex;
        G.verList[HeadIndex].next = newNode;
    }
}

void DeleteVex(Graph &G, char v)
{
    int index = Locate(v, G); // 该顶点的下标
    // 释放与该顶点有关的所有边
    Node *p = G.verList[index].next; // 临时指针p指向该顶点邻接表的第一个结点
    while (p != nullptr)
    {
        if (!G.isDireted) // G为无向图
        {
            Node *q = G.verList[p->index].next; // 临时指针q指向待删除结点所在邻接表中的第一个结点
            while (q->next->index != index)     // 一直找,直到找到q的next结点的index值为删除顶点的index
            {
                q = q->next;
            }
            Node *needDel = q->next; // 创建一个临时指针,指向待删除的结点
            q->next = needDel->next; // 保证邻接表不断
            free(needDel);           // 释放空间
        }
        G.verList[index].next = p->next;
        G.arcNum--;
        free(p);
    }
    // 释放顶点
    G.verList[index].nodeData = NULL;
    G.verList[index].next = nullptr;
    G.vertexNum--;
    return;
}

void DeleteArc(Graph &G, char tail, char head)
{
    int TailIndex = Locate(tail, G);
    int HeadIndex = Locate(head, G);
    Node *p = G.verList[TailIndex].next; // 临时指针p指向弧尾顶点邻接表的第一个结点
    while (p->next->index != HeadIndex)
    {
        p = p->next;
    }
    Node *needDel = p->next;
    p->next = needDel->next;
    free(needDel);
    G.arcNum--;
    if (!G.isDireted) // G为无向图
    {
        Node *q = G.verList[HeadIndex].next;
        while (q->next->index != TailIndex)
        {
            q = q->next;
        }
        needDel = q->next;
        q->next = needDel->next;
        free(needDel);
    }
}
void CreateGraph(Graph &G)
{
    cin >> G.vertexNum >> G.arcNum; // 输入顶点数和边数
    cin >> G.isDireted;             // 输入是否为有向图
    if (G.vertexNum > MaxSize)
    {
        return;
    }
    // 初始化顶点列表
    for (int i = 0; i < G.vertexNum; i++)
    {
        cin >> G.verList[i].nodeData;
        G.verList[i].next = nullptr;
    }
    // 依次输入各边的信息
    for (int j = 0; j < G.arcNum; j++)
    {
        char ArcHead, ArcTail;
        cin >> ArcTail >> ArcHead;
        InsertArc(G, ArcTail, ArcHead);
    }
}

void HNodeIndegree(Graph G)
{
    int IndegreeCnt[G.vertexNum] = {0};
    for (int i = 0; i < G.vertexNum; i++)
    {
        Node *tmp = G.verList[i].next;
        while (tmp != nullptr)
        {
            IndegreeCnt[tmp->index]++;
            tmp = tmp->next;
        }
    }
    cout << "all node's indegree" << endl;
    for (int j = 0; j < G.vertexNum; j++)
    {
        cout << G.verList[j].nodeData << ':' << IndegreeCnt[j] << endl;
    }
}

void HNodeOutdegree(Graph G)
{
    int OutdegreeCnt[G.vertexNum] = {0};
    for (int i = 0; i < G.vertexNum; i++)
    {
        Node *tmp = G.verList[i].next;
        while (tmp != nullptr)
        {
            OutdegreeCnt[i]++;
            tmp = tmp->next;
        }
    }
    cout << "all node's outdegree" << endl;
    for (int j = 0; j < G.vertexNum; j++)
    {
        cout << G.verList[j].nodeData << ':' << OutdegreeCnt[j] << endl;
    }
}

void MaxOutDegreeNode(Graph G)
{
    int index = -1; // 出度最大的数组下标
    int res = 0;    // 出度
    // 与HNodeOutdegree同
    // same code
    int OutdegreeCnt[G.vertexNum] = {0};
    for (int i = 0; i < G.vertexNum; i++)
    {
        Node *tmp = G.verList[i].next;
        while (tmp != nullptr)
        {
            OutdegreeCnt[i]++;
            tmp = tmp->next;
        }
    }
    // same code

    for (int j = 0; j < G.vertexNum; j++)
    {
        if (OutdegreeCnt[j] > res)
        {
            res = OutdegreeCnt[j];
            index = j;
        }
    }
    cout << "the max out degree is" << ':' << G.verList[index].nodeData << endl;
}

void ZeroOutdegree(Graph G)
{
    int cnt = 0;
    // same code
    int OutdegreeCnt[G.vertexNum] = {0};
    for (int i = 0; i < G.vertexNum; i++)
    {
        Node *tmp = G.verList[i].next;
        while (tmp != nullptr)
        {
            OutdegreeCnt[i]++;
            tmp = tmp->next;
        }
    }
    // same code
    for (int j = 0; j < G.vertexNum; j++)
    {
        if (OutdegreeCnt[j] == 0)
        {
            cnt++;
        }
    }
    cout << "the number of zero outdegree is" << ' ' << cnt;
}

bool IsArcExist(char a, char b, Graph G)
{
    int AIndex, BIndex; // 找到弧头和弧尾的数组下标
    for (int i = 0; i < G.vertexNum; i++)
    {
        if (G.verList[i].nodeData == a)
        {
            AIndex = i;
            continue;
        }
        if (G.verList[i].nodeData == b)
        {
            BIndex = i;
            continue;
        }
    }
    Node *tmp = G.verList[AIndex].next;
    while (tmp != nullptr)
    {
        if (tmp->index == BIndex)
        {
            return true;
        }
        tmp = tmp->next;
    }
    return false;
}

int main()
{
    Graph G;
    CreateGraph(G);
    // HNodeIndegree(G);
    // HNodeOutdegree(G);
    // MaxOutDegreeNode(G);
    // ZeroOutdegree(G);
    // char head, tail;
    // cin >> head >> tail;
    // bool isit = IsArcExist(head, tail, G);
    // cout << isit << endl;
    return 0;
}


//这个是邻接矩阵的完整代码
#include <stdio.h>
#include <iostream>

using namespace std;

#define Max 20
// 顶点信息
struct VertexItem
{
    char Vertex; // 顶点信息
    int index;   // 顶点在邻接矩阵中的下标
};
// 图的邻接矩阵存储
struct Graph
{
    int vertexNum;
    int arcNum;
    bool isDireted;
    int Matrix[Max][Max];
    VertexItem vertexList[Max]; // 顶点信息表
};
// 初始化图
void InitGraph(Graph &G)
{
    G.arcNum = 0;
    G.vertexNum = 0;
    for (int i = 0; i < Max; i++)
    {
        for (int j = 0; j < Max; j++)
        {
            G.Matrix[i][j] = -1;
        }
    }
}
// 获取顶点下标
int Locate(Graph G, char c)
{
    int res = -1;
    for (int i = 0; i < G.vertexNum; i++)
    {
        if (G.vertexList[i].Vertex == c)
        {
            res = G.vertexList[i].index;
        }
    }
    return res;
}
// 创造图
void CreateGraph(Graph &G)
{
    if (G.vertexNum > Max) // 输入的顶点数量超过最大值
    {
        return;
    }
    //
    for (int i = 0; i < G.vertexNum; i++)
    {
        for (int j = 0; j < G.vertexNum; j++)
        {
            G.Matrix[i][j] = 0;
        }
    }
    for (int i = 0; i < G.vertexNum; i++)
    {
        char vertex;
        cin >> vertex;
        G.vertexList[i].Vertex = vertex;
        G.vertexList[i].index = i;
    }
    char tail, head; // 弧尾和弧头
    for (int i = 0; i < G.arcNum; i++)
    {
        cin >> tail >> head;
        int tailIndex, headIndex;
        tailIndex = Locate(G, tail);
        headIndex = Locate(G, head);
        // G为有向图
        if (G.isDireted)
        {
            G.Matrix[tailIndex][headIndex] = 1;
        }
        // G为无向图
        else
        {
            G.Matrix[tailIndex][headIndex] = 1;
            G.Matrix[headIndex][tailIndex] = 1;
        }
    }
}
// 添加顶点
void InsertVex(Graph &G, char c)
{
    G.vertexList[G.vertexNum].Vertex = c;          // 顶点信息存入顶点表中
    G.vertexList[G.vertexNum].index = G.vertexNum; // 顶点的在邻接矩阵的索引存入顶点表中                            // 顶点数量加一
    // 对新插入的顶点对应的矩阵初始化
    for (int i = 0; i <= G.vertexNum; i++)
    {
        G.Matrix[G.vertexNum][i] = 0;
        G.Matrix[i][G.vertexNum] = 0;
    }
    G.vertexNum++;
}
// 删除顶点以及相关的边
void DeletVex(Graph &G, char c)
{
    int vexIndex = Locate(G, c);
    G.vertexNum--;
    for (int i = 0; i < G.vertexNum; i++)
    {
        if (G.Matrix[vexIndex][i] == 1) // 有边
        {
            G.Matrix[vexIndex][i] = 0;
            G.arcNum--;
        }
        if (G.Matrix[i][vexIndex] == 1)
        {
            G.Matrix[i][vexIndex] = 0;
        }
    }
    G.vertexList[vexIndex].index = -1;
}
// 添加弧
void InsertArc(Graph &G, char tail, char head)
{
    int tailIndex = Locate(G, tail);
    int headIndex = Locate(G, head);
    if (headIndex == -1 || tailIndex == -1) // 输入的弧头或者弧尾不存在
    {
        return;
    }
    G.Matrix[tailIndex][headIndex] = 1;
    G.arcNum++;
    if (!G.isDireted)
    {
        G.Matrix[headIndex][tailIndex] = 1; // 若不是有向图则再添加一条对称边
    }
}
// 删除弧
void DeleteArc(Graph &G, char tail, char head)
{
    int tailIndex = Locate(G, tail);
    int headIndex = Locate(G, head);
    if (headIndex == -1 || tailIndex == -1)
    {
        return;
    }
    G.Matrix[tailIndex][headIndex] = 0;
    G.arcNum--;
    if (!G.isDireted)
    {
        G.Matrix[headIndex][tailIndex] = 0; // 若不是有向图则再删除一条对称边
        G.arcNum--;
    }
}

int main()
{
    Graph G;
    InitGraph(G);
    cin >> G.vertexNum >> G.arcNum;
    cin >> G.isDireted;
    CreateGraph(G);
    InsertVex(G, '6');      // 插入新顶点6
    InsertVex(G, '7');      // 插入新顶点7
    InsertArc(G, '1', '6'); // 添加一条边,从1 -> 6
    InsertArc(G, '3', '6'); // 添加一条边,从3 -> 6
    InsertArc(G, '1', '7'); // 添加一条边,从1 -> 7
    InsertArc(G, '3', '7'); // 添加一条边,从3 -> 7
    DeletVex(G, '6');       // 删除顶点6以及其关联的所有边
    DeleteArc(G, '1', '6'); // 删除1->6的边
    return 0;
}

结束语

  因为是算法小菜,所以提供的方法和思路可能不是很好,请多多包涵~如果有疑问欢迎大家留言讨论,你如果觉得这篇文章对你有帮助可以给我一个免费的赞吗?我们之间的交流是我最大的动力!文章来源地址https://www.toymoban.com/news/detail-753765.html

到了这里,关于【数据结构与算法】分别以邻接矩阵和邻接表作为存储结构实现以下操作:1.增加一个新顶点v、2.删除顶点v及其相关的边、3.增加一条边<v,w>、4.删除一条边<v,w>的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【数据结构】邻接矩阵法

    顶点用一维数组Vex表示,其中可存放较为复杂的信息(如下标),边表用二维数组Edge表示,存放边的信息(两顶点之间有直接相连的边为1,否则为0)。  如何求顶点的入度 、出度? 对于无向图  第 i 个节点的度: 该结点所在行列的非0元素个数 对于有向图  第i个节点的

    2024年02月12日
    浏览(52)
  • 数据结构——图的基本定义以及图的存储结构,邻接矩阵,邻接表

    目录 图的定义和术语 图的存储结构 顺序存储结构—邻接矩阵 链式存储结构 邻接表 邻接多重表 十字链表 图的遍历 图的连通性问题 有向无环图及其应用 最短路径 图的定义:图是一种非线性的复杂的数据结构,图中的数据元素的关系是多对多的关系 ,在图中我们常常把数

    2024年02月04日
    浏览(41)
  • 24考研数据结构-图的存储结构邻接矩阵

    【1】顶点的结点结构 ——————— | data | firstarc | ——————— data数据域:储存顶点vi firstarc链域:指向链表中第一个结点 【2】弧的结点结构 —————————— | adjvex | info | nextarc | —————————— adjvex邻接点域:与顶点vi邻接的点在图中的位置 info数据域

    2024年02月14日
    浏览(44)
  • 数据结构——图篇(邻接矩阵、邻接表、深度优先搜索、广度优先搜索)

    描述 图比树更为复杂,展现的是一种多对多的关系,图的结构是任意两个数据对象之间都可能存在某种特定的关系的数据结构 概念 顶点 : 基本介绍 顶点集合表示为V集合,要求图中顶点至少要有一个,即V集合不能为空集。通常使用|V|来表示顶点的个数,通常使用E(V)来表示

    2024年02月04日
    浏览(30)
  • C++数据结构之图的存储结构——邻接矩阵和邻接表实现无向图

    关键点: 1.构建二维数组 2.对应边的位置赋值为1 由于比较简单就直接上代码: 个人对邻接表实现无向图的理解如下,仅供参考:         由于无向图的组成是由多个顶点和多条无向边组成的,因此我们可以把它拆分成两个结构,分别是顶点和无向边,又由于我们是使用

    2024年02月05日
    浏览(43)
  • 数据结构-邻接矩阵的创建与遍历

    上篇文章已经介绍了邻接矩阵的具体作用与如果利用邻接矩阵寻找相邻顶点,这次介绍重点为邻接矩阵的创建与两种遍历方式 邻接矩阵的创建 其结构体需要能记录顶点、顶点数、边数及邻接矩阵,即 创建方式则为读入边数、顶点数即各边的两个顶点和权值 图的遍历 DFS(深

    2024年02月20日
    浏览(36)
  • 【数据结构】图的创建(邻接矩阵,邻接表)以及深度广度遍历(BFS,DFS)

    图是由顶点集合及顶点间的关系组成的一种数据结构:G = (V, E),其中: 顶点集合V = {x|x属于某个数据对象集}是有穷非空集合; E = {(x,y)|x,y属于V}或者E = {x, y|x,y属于V Path(x, y)}是顶点间关系的有穷集合,也叫 做边的集合。 完全图:在有n个顶点的无向图中,若有n * (n-1)/2条边,

    2024年02月04日
    浏览(34)
  • [数据结构]:25-图深度优先遍历(邻接矩阵)(C语言实现)

    目录 前言 已完成内容 图深度优先遍历实现 01-开发环境 02-文件布局 03-代码 01-主函数 02-头文件 03-AdjMatrixFunction.cpp 04-DFS.cpp 结语         此专栏包含408考研数据结构全部内容,除其中使用到C++引用外,全为C语言代码。使用C++引用主要是为了简化指针的使用,避免二重指针的

    2023年04月10日
    浏览(37)
  • 【C++数据结构 | 图速通】10分钟掌握邻接矩阵 & 邻接表 | 快速掌握图论基础 | 快速上手抽象数据类型图

    by.Qin3Yu 请注意:严格来说,图不是一种数据结构,而是一种抽象数据类型。但为了保证知识点之间的相关性,也将其列入数据结构专栏。 本文需要读者掌握顺序表和单链表的操作基础,若需学习,可参阅我的往期文章: 【C++数据结构 | 顺序表速通】使用顺序表完成简单的成

    2024年02月05日
    浏览(32)
  • 数据结构学习记录——如何建立图(邻接矩阵、邻接表-图节点的结构、创建并初始化、插入变、完整图的建立)

    目录 邻接矩阵 图节点的结构 创建并初始化 插入边 完整的图的建立  邻接表 图节点的结构 创建并初始化 插入边  完整的图的建立  定义结构体GNode,其中包含以下成员变量: Nv:表示图中的顶点数。 Ne:表示图中的边数。 二维数组表示图的邻接矩阵。它的大小是MaxVertexN

    2024年02月06日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包