SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void sortList() {  
  2.         Node current = null, index = null;  
  3.         int temp;  
  4.         //Check whether list is empty  
  5.         if(head == null) {  
  6.             return;  
  7.         }  
  8.         else {  
  9.             //Current will point to head  
  10.             for(current = head; current.next != null; current = current.next) {  
  11.                 //Index will point to node next to current  
  12.                 for(index = current.next; index != null; index = index.next) {  
  13.                     //If current's data is greater than index's data, swap the data of current and index  
  14.                     if(current.data > index.data) {  
  15.                         temp = current.data;  
  16.                         current.data = index.data;  
  17.                         index.data = temp;  
  18.                     }  
  19.                 }  
  20.             }  
  21.         }  
  22.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top