Link list swaping

A link list problem, i need some how to sort and print out an object by surname in alphabetical order.
i have a try to do that by this code not working for swamping i should i go about that?
May another way of swapping using pointer instead?

void functions::printdata()
{

for(node* temp1=head;temp1!=NULL;temp1=temp1->next)
{
for(node* temp2=head;temp2!=NULL;temp2=temp2->next)
{
if(temp2->client.getsurname() > temp1->client.getsurname())
{
clienttype swap=temp1->client;
temp1->client=temp2->client;
temp2->client=swap;
}
}

}
You might be doing the swapping twice. Try to do the second for loop not from head, but from temp1->next.
Topic archived. No new replies allowed.