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);

}

}

Node :: Node ( int n )

{

head = new Node ;

head -> dat = n ;

head -> next = NULL ;

tail = head ;

} // end of constructor ()

It will make a single node and in your main () function, all the elements of nlist will be linked-lists having one node each.

This was just to help you how to get started.

Mayank.