Answer the question
In order to leave comments, you need to log in
How to reset pointers between nodes in a singly linked list to swap elements?
It is necessary to swap elements for selection sorting. There is the following function
void Sort()
{
node *h = HEAD, *i, *j, *next_i;
for(i = h; i!=NULL && i->NEXT!=NULL; i=i->NEXT)
{
node *min;
min = i;
for(j = i->NEXT; j!=NULL ; j=j->NEXT)
{
if(j->DATA < min->DATA)
min=j;
}
if(min!=i)
{
int temp;
temp = min->DATA;
min->DATA = i->DATA;
i->DATA = temp;
}
}
HEAD = h;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question