Another linked list question (infinately repeating loop)

Heya. I wrote a program that asks the user for a series of integers, and the program would return them in ascending order. When I run this linked list program, it simply takes the first integer, the lowest one, and repeats it indefinitely.

I don't know what code to supply and don't wish to flood the board with everything I think could be amiss. Since it takes place in a print function, I'll post that code.

1
2
3
4
5
6
7
8
9
10
11
12
13
template <class Type>
void linkedListType<Type>::print() const
{
     nodeType<Type> *current;      //pointer to traverse the list
     
     current = first;              //set current node so it points to the first 
     
     while (current != NULL)  //while we have more data to print
     {
           cout << current->info << " ";
           current = current->link;
           }
           }


Some more code. This defines the node:
1
2
3
4
5
template <class Type>
struct nodeType {
       Type info;
       nodeType<Type> *link;
};


Here's the linked list iterator, so you can see where current comes from:
1
2
3
4
5
6
7
8
9
10
11
12
template <class Type>
class linkedListIterator {
public:
       linkedListIterator();
       linkedListIterator(nodeType<Type> *ptr);
       Type operator*();
       linkedListIterator<Type> operator++();
       bool operator==(const linkedListIterator<Type>& right) const;
       bool operator!=(const linkedListIterator<Type>& right) const;
private:
        nodeType<Type> *current;   //pointer to point to the current node in the linked list.
};


I can obviously supply more code if needed.
Last edited on
Does one of your functions in the linkedListIterator have a pointer to the next node? I ask because it seems that there is only information regarding the current node, but in order to add information to the next node, you must have a pointer to it. If there isn't, it would be set to NULL.
You know, a funny thing happened while running the program on this computer, which is not the same as the one I usually do C++ work... The program worked. Actually, it's still got a couple problems, but not the one I was just having. I'll retry again on the other machine before considering this problem solved, though. Thanks anyways!
Topic archived. No new replies allowed.