Trying to sort a linked list. I have two classes.
class listNode {
public:
int coef;
int expo;
listNode *next;
};
class LList {
private:
listNode *head;
listNode *tail;
public:
void read()
void sort();
};
I read in the two numbers coef and expo. I need to sort it in accending order by expo. My sort function is
void LList::sort() {
listNode *temp;
listNode *temp2;
temp = head;
temp2 = temp->next;
int CC = 0;
// counter is global and is size of list
while(CC != counter) {
if(temp->expo <= temp2->expo) {
head = temp2;
head->next = temp;
}
CC++;
}
}
It goes into an infinite loop then crashes.
Anyone offer advice on the problem? Thanks