Cannot stop printList while loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void LinkedList::printList()
{
    cout << "\nEntered printList..." << endl;
    int count = 0;
    node * p = head;
    node * q = head;
    cout << "\n---------------------\n";
    cout << " Car List\n";
	while (q)
    {
        p = q;
        cout << "---------------------\n";
        cout << "\t position: " << count << "\n";
        cout << "\t name: " << p -> name << "\n";
        cout << "\t ICnumber: " << p -> ICnumber << "\n";
		cout << "\t Plate Number: " << p -> plate << "\n";
		cout << "\t Model: " << p -> model << "\n";
		cout << "\t Engine Capacity: " << p -> capacity << "\n";
		cout << "\t Color: " << p -> color << "\n";
		cout << "\t Year Manufactured: " << p -> yearmanufactured<<"\n";
        q = p -> next;
        count++;
    }
}
Last edited on
http://www.eelis.net/iso-c++/testcase.xhtml (points 3, 6 and 7)
At a glance it doesn't seem incorrect. Look at how you are constructing your list, you may be creating a loop.
Topic archived. No new replies allowed.