i have a very big problem with my read function it has to get constant and exponent values from the user and creates a linked list but this linked list should be sorted the problem occurs when i sort them pls check my code :

Code:

void Poly::read()
{
int Constant,Exponent;
int end = 0;
int counter = 0;
List *currentptr,*new_node,*temp;
currentptr = new List;
currentptr = head;
cout<<"\nEnter 0 to constant to exit\n";
do
{
cout<<"\nEnter constant:";
cin>>Constant;
cout<<"\nEnter exponent:";
cin>>Exponent;
currentptr->set_constant(Constant);
currentptr->set_exponent(Exponent);
new_node = new List;
currentptr->next = new_node;
currentptr = currentptr->next;
counter++;
} while(Constant !=0);
currentptr = head;
//sorting
while(end < counter)
{
while(currentptr->next != NULL)
{
if(currentptr->get_exponent() < currentptr->next->get_exponent())
{
temp = new List;
temp->set_constant(currentptr->next->get_constant());
temp->set_exponent(currentptr->next->get_exponent());
currentptr->next->set_exponent(currentptr->get_exponent());
currentptr->next->set_constant(currentptr->get_constant());
currentptr->set_exponent(temp->get_exponent());
currentptr->set_constant(temp->get_constant());
delete temp;
}
end++;
currentptr = currentptr->next;
}
currentptr = head;
}