I dont know if this helps you but I created a linked list program that does the same as I think you want to acheive.
Code:
#include <iostream.h>
class Node
{
public:
Node(): itsNext(0), itsKey(0) {}
~Node() {}
void Insert (Node * theNode);
int getKey()const { return itsKey; }
void setKey(int key) { itsKey = key; }
void Show();
private:
Node *itsNext;
int itsKey;
};
void Node::Insert(Node *theNode)
{
if (itsNext == 0)
itsNext = theNode;
else
itsNext->Insert(theNode);
}
void Node::Show()
{
cout << itsKey;
if (itsNext == 0)
return;
itsNext->Show();
}
class LinkedList
{
public:
LinkedList(): itsHead(0) {}
void Insert(Node *theNode);
void Show();
private:
Node * itsHead;
};
void LinkedList::Insert(Node *theNode)
{
if (itsHead == 0)
itsHead = theNode;
else
itsHead->Insert(theNode);
}
void LinkedList::Show()
{
if (itsHead == 0)
return;
itsHead->Show();
}
int main()
{
LinkedList theList;
Node *theTemp;
for (int i = 0; i < 10; i++)
{
theTemp = new Node;
theTemp->setKey(i);
theList.Insert(theTemp);
}
theList.Show();
return 0;
}