Insertion sort implemented in Javascript


   function insertSort(array){
	   for(i=1, n=array.length; i<n; i++){
   	        key = array[i];
                j=i-1;
                while(j > -1 && key < array[j]){
                     array[j+1]=array[j];
                     j--;
                }
                array[j+1]=key;
	   }
          return array;
   }


Insertion sort on Wikipedia

Comments (0)

RSS Collapse / Expand

Only registered and authorized users can leave comments. Login or Register