Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. //Calls a selection sort on the list
  2. listNode* sort (listNode* head)
  3. {
  4.   if(head->next == NULL)
  5.     return head;
  6.  
  7.   listNode* sortLead = head;
  8.   listNode* smallest = sortLead;
  9.   listNode* curr = sortLead->next;
  10.  
  11.   while(sortLead->next != NULL)
  12.     {
  13.       while(curr != NULL)
  14.     {
  15.       if(curr->data->freq < smallest->data->freq)
  16.         {
  17.           swap(curr, smallest);
  18.         }
  19.       curr = curr->next;
  20.     }
  21.       swap(sortLead, smallest);
  22.       sortLead = sortLead->next;
  23.       smallest = sortLead;
  24.       curr = sortLead->next;
  25.     }
  26.  
  27.   return head;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement