I have made an insertion sort function for a doubly linked list of polynomials , i cant figure out the error , please help me with it!

void insertionSort()
	{
		node* temp=head;	
		
		while(temp->next != NULL)
		{
			node* second =temp->next;
			if (second->exponent==temp->exponent)
			{
				temp=temp->next;
			}
			else
			{
				second->previous->next=second->next;
				second->next->previous=second->previous;
				
				if (head->exponent > second->exponent)
				{
					second->next=head;
					second->previous=NULL;
					head->previous=second;
					head= second;
				}
				node* current = head->next;
			
				while(current->exponent < second->exponent)
				{
					current=current->next;
				}
				second->next=current;
				second->previous=current->previous;
				current->previous->next=second;
				current->previous=second;
			}
		}
	}

Read your compiler's error message, it should tell you the line (within a line or 2) and what you did. You're not going to get much help here unless you share the error message.

Edited 6 Years Ago by Fbody: n/a

Read your compiler's error message, it should tell you the line (within a line or 2) and what you did. You're not going to get much help here unless you share the error message.

There are no errors , but the it go stuck at the line
node* temp =head

Okay, what is "head"? I don't see a declaration. Where did it come from?

Edited 6 Years Ago by Fbody: n/a

Okay, what is "head"? I don't see a declaration. Where did it come from?

class node 
{
public:
	
	char variable;
	int exponent;
	Fraction coefficient;
	node* next;
	node* previous;
	
	node()
	{
		variable='x';
		exponent=0;
	}
	
};

class list
{
	node* head;
	node* tail;
	int count;

public:

You didn't answer my question. I didn't ask for the class definition, I know that it should be a "node". I asked where and how you declared the object/variable called "head".

Based on what I see in the OP, you're trying to get information from/about an object that does not exist within the scope of insertionSort().

You didn't answer my question. I didn't ask for the class definition, I know that it should be a "node". I asked where and how you declared the object/variable called "head".

Based on what I see in the OP, you're trying to get information from/about an object that does not exist within the scope of insertionSort().

Sorry i dint get you.

Do you understand the concept of scope? Have you ever heard the term before now?

Based on your original post, the variable "head" is not in scope. It's that simple. You need to find a way to bring "head" into scope before you try to do anything with it.

Do you understand the concept of scope? Have you ever heard the term before now?

Based on your original post, the variable "head" is not in scope. It's that simple. You need to find a way to bring "head" into scope before you try to do anything with it.

head is in scope , sort function is in the list class.

head is in scope, sort function is in the list class.

Ok, now we're getting somewhere.

What makes you think the error is in the line you mentioned? Do you get a message from the compiler that says there is an issue there?

Based on this response, I don't see why there would be an error there. Since head is a private member, insertionSort() should have access unless the function is not correctly associated with the class.

Edited 6 Years Ago by Fbody: n/a

This question has already been answered. Start a new discussion instead.