Hi,
Im having a problem while trying to create a link list from a given array. So I
made a link list constructor called Set like this:
Set::Set(int a[], int n)
{
Set();
Node *cur = header;
for(int i = 0; i<n; i++)
{
Node *newNode = new Node(a[i], NULL);
cur->next = newNode;
cur = cur->next;
}
}
The node constructor parameters are an int value and a pointer to the next Node
like this:
Node::Node (int nodeVal, Node *nextPtr) : value (nodeVal), next (nextPtr)
It compiled but when i run it, the program somehow creating an infinite loop of
link list. Node cur has next node, and it also has next node and so on.
Anyone know why this happen? Which part do I miss?
Thank you in advance
Regards
Jos Timanta Tarigan