cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Link list swaping
Link list swaping
Oct 2, 2013 at 10:22pm UTC
sirsyltan
(3)
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;
}
}
}
Oct 3, 2013 at 3:52am UTC
ats15
(423)
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.