I'm not very advanced in the sorting part of programming yet, so I was looking for some help with my algorithm.
void sortList()
{
Item_PTR tmpNxt = current->nextItem;
Item_PTR tmpPTR = current;
int a, tmp;
while(tmpNxt != NULL)
{
a = tmpPTR->value;
while(tmpNxt != tmpPTR && tmpNxt->value < a)
{
tmp = a;
tmpPTR->value = tmpNxt->value;
tmpNxt->value = tmp;
tmpPTR = tmpPTR->nextItem;
}
tmpPTR = current;
tmpNxt = tmpNxt->nextItem;
}
}
The list state before sorting: 9 8 7 6 5 4 3 2 1 after sorting: 1 9 8 7 6 5 4 3 2
I'm not sure why...I've played computer a lot on paper and I feel like it should work...but maybe other eyes will spot the problem.
Current is a global pointer that will always have the location of the first/ top element in the list.