I was having problems with this program before but pushed through most of them. However, I keep encountering a run-time error when my "Kill" function is called.
It's supposed to take the order that the nodes should be deleted as a parameter. (For example if the order is 2, every second node should be deleted until only one is left.) I have the list linked circularly so the last node's next node is the beginning node. Is there something I'm missing here?
or are you trying to declare 3 nodeptr's nodePtr cursor, First, temp;
in your constructor you cannot have cursor = cursor->next; because you have not declared what next points. You tell it what the info should be but not next. if cursor is a new node then how can cursor = the node it points to if it just came into existence
#include <iostream>
#include "LinkedList.h"
usingnamespace std;
int main()
{
int captives, killOrder;
cout << "Enter the number of captives: ";
cin >> captives;
LinkedList circle(captives);
cout << endl << "Now enter the order that they will be killed: ";
cin >> killOrder;
circle.Kill(killOrder);
return 0;
}
So I'm thinking it would be beneficial to remove preCursor completely from the ctor, as well as the cursor = cursor->next line, then write a separate function to put the nodes into order. I suppose I'll give that a try.