I'm trying to implement a selection sort algorithm on linked lists, and the trouble I've ran into is swapping any two nodes in the linked list.
My selection sort function:
I'm sure I'd need at least one temporary node, but even then I'm still unsure about how I'm going to tackle this problem.Code:void selSortLL(NodeT *head) { NodeT *cur = NULL; NodeT *move = NULL; NodeT *min = NULL; if (head == NULL || head->next == NULL) { return head; } for (cur = head; cur->next != NULL; cur=cur->next) { min = cur; for (move = cur->next; move != NULL; move=move->next) { if (move->value < min->value) { min = move; } } if (min != cur) { //SWAP CUR W/ MIN NODES } } return head; }



1Likes
LinkBack URL
About LinkBacks



