Here's the code I have:
Expand|Select|Wrap|Line Numbers
- void Polynomial::orderDescending(){
- Polynomial newPoly;
- newPoly.head = this->head;
- Term * temp1 = this->head;
- Term * temp2 = temp1->next;
- for (int pass = 1; pass < this->numTerms; pass++) {
- for (int count = 0; count < this->numTerms-1; count++) {
- if (temp1->deg < temp2->deg) {
- temp1->next = temp2->next;
- temp2->next = temp1;
- if (count = 0) {
- this->head = temp2;
- }
- temp2 = temp1->next;
- }
- else{
- temp1 = temp1->next;
- temp2 = temp2->next;
- }
- }
- temp1 = this->head;
- temp2 = temp1->next;
- }
- }
Specifically, line 16 didn't seem to change the linked list which I wanted to implement in line 27.
For example I have the linked list (the data denotes the degree I want to arrange):
4 -> 5 -> 7
After the first inner loop ends, I want the linked list to be changed to
5 -> 7 -> 4.
This doesn't happen in the code.
Instead the list became
7->4 only.
Can anyone check how to correct my code?
Thanks