C++双链表 我是C++新手,我在寻求帮助!我正在尝试使用DLL实现带加权路径的有向图。我不能检查我的实现,因为我没有什么问题,我不知道如何解决它

C++双链表 我是C++新手,我在寻求帮助!我正在尝试使用DLL实现带加权路径的有向图。我不能检查我的实现,因为我没有什么问题,我不知道如何解决它,c++,C++,我的代码: #include <iostream> #include <vector> #include <set> #include <stdio.h> #include <time.h> #include <math.h> #include <iostream> #include <fstream> #include <sstream> #include <cstring>

我的代码:

#include <iostream>
#include <vector>
#include <set>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <climits>
#include <algorithm>

using namespace std;
   typedef struct Node Node;
typedef struct Edge Edge;
typedef struct DLList DLList;



struct Node
{
    int id;
    int dist;
    Node* prev;
    vector<Edge*> edges;
};

struct Edge
{
    int length;
    Node* to;
};

struct DLList
{
    DLList *next;
    DLList *prev;
    Node* val;
};

Node* g_firstNode = 0;
Node* g_currentNode = 0;
DLList* first = 0;
DLList* last = 0; 

Node* getFirst()
{
    if(first == 0)
    {
        cout << "Pusta lista " << endl; 
    }
    return first->val;
}

DLList* add(Node* n)
{
    DLList* newNode = new DLList;
    if(first == 0)
    {
        last = 
        newNode->val = n;
        newNode->next = 0;
        newNode->prev=0;
        first =  newNode;       
    }
    else
    {
        last =
        newNode->val = n;
        newNode->next = 0;
        newNode->prev=last;
        last->next=newNode;
    }
}

void removeFirst()
{
    if(first!=0)
    {
        first = first->next;
        if(first != 0)
        {
            first->prev = 0;        
        }   
    }
}


void remove(DLList* e)
{
    if(e==first)
    {   
        removeFirst();
    }
    else if(e==last)
    {
        last = last->prev;
        last -> next = 0;
    }
    else
    {
        e->prev->next = e->next;
        e->next->prev = e->prev;
    }
}

void remove(Node* n)
{
    if(n==first->val)
    {
        removeFirst();
    }
    else if(n==last->val)
    {
        last = last->prev;
        last->next = 0; 
    }
    else
    {
        for(DLList* i=first; i!=0; i=i->next)
        {
            if(n==i->val)
            {   
                i->prev->next = i->next;
                i->next->prev = i->prev;
                break;
            }       
        }   
    }
}

bool isEmpty()
{
    return first == 0;
}

int main()
{
    Node* start = 0;
    Node* end = 0;
    Node* newNode = new Node;
    vector<Node*> nodes(5);
    int maxlen=0,i=0,j=0,from=0,n_edges=18,n_nodes=5;

    for(i=0; i<n_nodes;i++)
    {
        newNode->id = n_nodes;
        nodes[n_nodes] = newNode;
    }
    Edge* newEdge = new Edge;
    newEdge->length=5;
    newEdge->to=nodes[4];
    nodes[0]->edges.push_back(newEdge);

    return 0;
}

在节点结构中使用Edge之前,需要先定义它。

第一个编译器错误非常简单,为什么不解决这个问题呢?不知道第57行和第65行中裸last=的用途是什么。为什么不使用标准的库容器,比如std::vector。我正在实现这个算法:但是link中是一个java代码,我不知道如何在这个代码中使用last=类似,但是在java中,last=first=new DListEn;同一类型的最后一个和第一个数据列表。。。在您的案例中,last=newNode->val=n;其中最后一个是DLList*,分配给newNode->val,类型为Node*@Coda17,他不能在节点之前定义Edge,因为节点使用Edge;Bart需要声明Edge,并带有向前声明,如:struct Edge;在节点中使用它之前。
graph.cpp:57:18: error: cannot convert ‘Node*’ to ‘DLList*’ in assignment
graph.cpp:65:18: error: cannot convert ‘Node*’ to ‘DLList*’ in assignment