Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 0.48 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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