页面树结构

2017-07-25 Apache Spark 2.2.0 官方文档中文版发布 : http://spark.apachecn.org/docs/cn/2.2.0/


MachineLearning 优酷地址 : http://i.youku.com/apachecn

转至元数据结尾
转至元数据起始

Scala
package DataStructureAndAlgorithm

/**
  * Created by jiangzl on 2016/10/28.
  */
object BubbleSort {

  // 外层循环做拆分
  def bubbleSort(l: List[Int]): List[Int]  = l match {
    case List() => List()
    case head :: tail => bSort(head, bubbleSort(tail))
  }
  // 内层循环做排序
  def bSort(data: Int, dataSet: List[Int]): List[Int] = dataSet match {
    case List() => List(data)
    case head :: tail => if (data <= head) data :: dataSet else head :: bSort(data, tail)
  }

  def main(args: Array[String]) {
    val list = List(3, 12, 43, 23, 7, 1, 2, 20)
    println(bubbleSort(list))
  }
}

结果
List(1, 2, 3, 7, 12, 20, 23, 43)