私は隣接リストを作成しようとしています。私が書いたコードは以下の通りです。は、割り当てで 'リスト*'を 'ノード*'に変換できません。
struct Node
{
int dest;
struct Node* next;
};
struct list
{
struct list *head;
};
クラスは次のように定義されますエラーがこれらの関数である
class Graph
{
private:
int vertix;
list *arr;
public:
Graph(int v)
{
vertix = v;
arr = new list [vertix];
for(int i=0;i<vertix;i++)
{
arr[i].head=NULL;
}
}
Node* getNewNode(int destination)
{
Node* newNode = new Node;
newNode->dest = destination;
newNode->next = NULL;
return newNode;
}
:
void addEdge(int src, int dest)
{
Node* newNode = getNewNode(dest);
newNode->next = arr[src].head;
arr[src].head = newNode;
newNode = getNewNode(src);
newNode->next = arr[dest].head;
arr[dest].head = newNode;
}
void print()
{
cout<<"Adjacency list of vertix: "<<endl;
for(int i = 0; i< vertix; i++)
{
Node *ptr = arr[i].head;
cout<< i << "-->";
while(ptr)
{
cout<< "-->"<<ptr->dest;
ptr=ptr->next;
}
cout<<endl;
}
}
};
私が取得エラーメッセージは次のとおりです。 [エラー]「リストは*変換することはできません'to' Node * 'to assignment [エラー]初期化で'リスト* 'を'ノード* 'に変換できません
へ:これは、この行でエラーが発生しますリストは自分で作成し、std :: listも使うことができます。 – KimKulling
これらのメッセージはどの回線にありますか? – alexeykuzmin0
'list'構造体に' list'ではなく 'Node'へのポインタがあるように見えます。 – alexeykuzmin0