fueanta

bubble sort func. for singly linked lists

Dec 2nd, 2016
150
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // bubble sort func. for singly linked list
  2.  
  3. void sort(nodePtr node) {
  4.     nodePtr temp = node; bool flag = true;
  5.     while (flag) {
  6.         flag = false;
  7.         while (node->next != NULL) {
  8.             if (node->data > node->next->data) {
  9.                 swap(node->data, node->next->data);
  10.                 flag = true;
  11.             }
  12.             node = node->next;
  13.         }
  14.         node = temp;
  15.     }
  16. }
RAW Paste Data