SHARE
TWEET

Untitled

a guest Feb 27th, 2012 15 Never
  1. def insertionSort(unsortedList : List[String]) = {
  2.     val F = unsortedList.toArray
  3.     for(i <- (2 until F.length)){
  4.       val m = F(i)
  5.       var j = i;
  6.       while(j > 1 && !sorted){
  7.         if (F(j-1) >= m) {
  8.           F(j) = F(j-1)
  9.           j -= 1
  10.         }
  11.       }
  12.       F(j) = m
  13.     }
  14.     F.toList
  15.  }
  16.  
  17. // Note:
  18. // This algorithm has been transcribed from:
  19. // Saake and Sattler. "Algorithmen und Datenstrukturen. Eine Einf├╝hrung in Java".
  20. // dpunkt.verlag Heidelberg, 2004. page 123f
RAW Paste Data
Top