Solved

# linked list

Posted on 2003-03-19

I'm trying to create an array of linked list .

which looks like this

arr[0] = 1 -> 2 -> NULL;

meaning in arr[0] i have "data 1" pointing to "data 2";

How do i insert into the array. my trouble is in understanding the insertion

of a linked list into the array.

Thank you

#include <iostream.h>

class Node {

int dat;

Node* next;

public:

Node(int );

int disp() { return dat; }

};

Node *head, *tail;

Node::Node(int n)

{

for(i=0;i<=n;i++)

{if(head = NULL)

{head = nlist;} //I'm assuming i have to get the nlist but i do not know how.

else

{tail->next = nlist;}

tail = nlist;

nlist->next = NULL;

cout << tail->data;

}

int main() {

int n;

cin >> n;

Node** nlist;

nlist = new Node*[n];

for(int i(0); i < n; ++i) {

nlist[i] = new Node(i);

}

}