Okay, I am having some trouble with (2). Here is the code I have thus far (the reason I have the excessive cout and system("Pause") functions is because I am still debugging it):
Code:
void sortList (NodePtr dataPtr, NodePtr currPosition)
{
NodePtr current = dataPtr;
NodePtr newList = new NodeType;
int length = 0;
do
{
length++;
current = current->link;
} while (current->link != NULL);
length++;
current = dataPtr;
int passes = 0;
NodePtr current2 = newList;
while (length >= 0)
{
NodePtr smallest;
for (int count = 1; count < length; count++)
{
NodePtr temporary = new NodeType;
temporary->component = current->component;
cout << "The value of the temporary NodePtr is: " << temporary->component << endl;
current = current->link;
system("Pause");
if (count == 1 || temporary->component < smallest->component)
{
smallest = temporary;
cout << "The value of the smallest NodePtr, thus far, is: " << smallest->component << endl;
system("Pause");
}
}
if (passes == 0)
{
newList->link = smallest;
newList = smallest;
passes++;
}
else
{
cout << "The value of the first NodePtr in newList is: " << newList->component << endl;
system("Pause");
current2->link = smallest;
cout << "The value of the last NodePtr in newList is, for now: " << current2->link->component << endl;
system("Pause");
passes++;
current2 = current2->link;
}
delete smallest;
length--;
}
dataPtr = newList;
}
I know I still need to set currPtr, but I am holding off on that until I get this working.