2
我想动态地创建一个大小为'n'的数组,其中可以包含指向多个邻接列表的指针。然而,当我运行我的代码,它不会导致节点的阵列,它只是导致了这一点:如何动态创建指针数组?
这不是一个阵列,它只是一个节点。
这里是我的代码:
的main.cpp
#include "graph.h"
using namespace std;
int main() {
graph g;
return 0;
}
graph.cpp
#include "graph.h"
// Constructor
graph::graph()
{
int size = 5; //
// Allocate array of size (n) and fill each with null
adjListArray = new node*[size];
// Set each entry in array to NULL
for (int i = 0; i < size; i++)
{
adjListArray[i] = NULL;
}
}
graph.h
#include<cassert>
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct node
{
int name;
node *next;
};
class graph
{
public:
// Constructors/destructors
graph();
~graph();
private:
node** adjListArray; // Array of pointers to each adjacency list
};
我要去哪里错了?
不知道我看到任何问题。这可能是您的调试器代表数据的问题......以及是否可以强制它将adjListArray显示为数组。请记住,你显示的属性没有被声明为一个数组,而是作为'node **'声明的。 – jsantander