C++ 需要帮助了解哪些语法适用于我的数据结构吗

C++ 需要帮助了解哪些语法适用于我的数据结构吗,c++,list,vector,syntax,adjacency-list,C++,List,Vector,Syntax,Adjacency List,我正在尝试使用链接列表数组实现相邻列表: vector< list<Edge> > adjList; 下面是文件Graph.h中的类声明(对于所有的注释,我很抱歉,我想把我所有的想法都留在我的代码上,直到我准备把它交上来……) #包含ifndef图 #定义包含的图形 //类别优先权; #包括 #包括 #包括 #包括 使用名称空间std; 类图 { 公众: 图(); ~Graph(); /*void setArray(字符串顶点); void sortArray(); G

我正在尝试使用链接列表数组实现相邻列表:

vector< list<Edge> > adjList;
下面是文件Graph.h中的类声明(对于所有的注释,我很抱歉,我想把我所有的想法都留在我的代码上,直到我准备把它交上来……)

#包含ifndef图
#定义包含的图形
//类别优先权;
#包括
#包括
#包括
#包括
使用名称空间std;
类图
{
公众:
图();
~Graph();
/*void setArray(字符串顶点);
void sortArray();
Graph*getGraph(字符串前缀、字符串顶点、整数权重);
void集合图(字符串顶点、字符串后顶点、整数权重)*/
无效集_边(字符串targetVertex、字符串顶点、整数权重);
朋友类优先;
私人:
阶级边缘
{
公众:
边(字符串顶点,整数权重)
{m_顶点=顶点;m_权重=权重;}
~Edge();
字符串get_vertex(){}
int get_weight(){}
私人:
弦m_顶点;
单位重量;
};
向量adjList;
};
#endif//包含图形
这里是Graph.cpp

#include "Graph.h"

void Graph::set_Edge(string targetVertex, string vertex, int weight) //find target vertex
{
    for(unsigned int u = 0; u <= adjList.size(); u++)//traverses through the Y coord of the 2D array
    {
        if(targetVertex == adjList[u].m_vertex) // <<THIS IS WHERE THE ERROR OCCURS!!!!
        {
            adjList[u].push_back(Edge(vertex, weight)); //push new element to the back of the linked list at array index u.
        }

    }
    //we now need to add
    //adjList[adjList.size()].push_back(Edge(vertex, weight));
}
#包括“Graph.h”
void Graph::set_Edge(string targetVertex,string vertex,int-weight)//查找目标顶点
{

对于(unsigned int u=0;uadjList的类型为
list
,因此它没有任何名为
m_-vertex
的成员。它包含的节点具有
m_-vertex
成员

#include "Graph.h"

void Graph::set_Edge(string targetVertex, string vertex, int weight) 
{
    for(unsigned int u = 0; u <= adjList.size(); u++)
    {
        if(adjList[u].front().m_vertex == targetVertex)  
                   //^^add front() to access a list node 
                   //because the m_vertex member is same of all the edges in the list
                   //So just access the first one for simplicity.
        {
            adjList[u].push_back(Edge(vertex, weight)); 
        }
    }
}
#包括“Graph.h”
void图::set_边(字符串targetVertex、字符串顶点、整数权重)
{

对于(unsigned int u=0;u),您的向量包含列表。您在向量的元素上循环。因此,您迭代的每个元素都是…列表!而不是边或其他任何东西。
#include "Graph.h"

void Graph::set_Edge(string targetVertex, string vertex, int weight) //find target vertex
{
    for(unsigned int u = 0; u <= adjList.size(); u++)//traverses through the Y coord of the 2D array
    {
        if(targetVertex == adjList[u].m_vertex) // <<THIS IS WHERE THE ERROR OCCURS!!!!
        {
            adjList[u].push_back(Edge(vertex, weight)); //push new element to the back of the linked list at array index u.
        }

    }
    //we now need to add
    //adjList[adjList.size()].push_back(Edge(vertex, weight));
}
#include "Graph.h"

void Graph::set_Edge(string targetVertex, string vertex, int weight) 
{
    for(unsigned int u = 0; u <= adjList.size(); u++)
    {
        if(adjList[u].front().m_vertex == targetVertex)  
                   //^^add front() to access a list node 
                   //because the m_vertex member is same of all the edges in the list
                   //So just access the first one for simplicity.
        {
            adjList[u].push_back(Edge(vertex, weight)); 
        }
    }
}