C++ 如何从图形中删除圆弧?

C++ 如何从图形中删除圆弧?,c++,C++,我的图表有以下结构: struct vertex{ string nameV; string type; int serial; string core; string user; struct vertex *sigV; struct arc *subListArcs; vertex(string n,string t, int s, string c,string u){ nameV=n; typ

我的图表有以下结构:

struct vertex{
    string nameV;
    string type;
    int serial;
    string core;
    string user;
    struct vertex *sigV;
    struct arc *subListArcs;
    vertex(string n,string t, int s, string c,string u){
        nameV=n;
        type=t;
        serial=s;
        core=c;
        user=u;
        sigV=NULL;
        subListArcs=NULL;
    }
    bool visited;
}*graph;

struct arc{
    int megabyte;
    string destination;
    struct arc *sigA;
    arco(int m, string d){
        megabyte=m;
        destination=d;
        sigA=NULL;
    };
};
这个函数可以在每个向量的子istarcs中找到弧:

void deleteArc(string origin, string destination){
    struct vertex *tempV=graph;
    while(tempV!=NULL){
        if(tempV->nameV == origin){
            struct arc *tempA=tempV->subListArcs;
            while(tempA!=NULL){
                if(tempA->destination==destination){

                    tempA=NULL;

                    return;
                }
                tempA=tempA->sigA;
            }
        tempV=tempV->sigV;
        }
    }
}
我的想法是使用tempA=NULL来删除它,但这并不容易。
有人知道如何删除弧吗?

由于弧列表是单独链接的,您不仅需要找到要删除的目标弧,还需要在列表中找到它的上一个弧,因为删除目标时需要将上一个弧链接到下一个弧

        struct arc *tempA = tempV->subListArcs;
        struct arc *prevA = NULL; // <------- will track previous arc
        while(tempA != NULL){
            if(tempA->destination==destination){
                // caught
                if(prevA == NULL){  // arc to remove is first in list
                    tempV->subListArcs = tempA->sigA; // next becomes first in list
                } else {
                   prevA->sigA = tempA->sigA; // <--- link previous to next
                }
                // now delete the arc removed from list, and return
                delete tempA;
                return;
            }
            prevA = tempA;      // <-- keep track of the previous
            tempA=tempA->sigA;
        }
struct arc*tempA=tempV->subListArcs;
结构弧*prevA=NULL;//目的地==目的地){
//抓住
如果(prevA==NULL){//要删除的弧位于列表的第一位
tempV->subListArcs=tempA->sigA;//下一个成为列表中的第一个
}否则{
PREVA- > SIGA = TEMPA~> SIGA;/ /学习使用C++和显著