摘要: // 快速排序:它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小, // 然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据变成有序序列。 def quickSort(a:List[Int]):List[Int]={ if (a.length a.head)... 阅读全文
posted @ 2017-12-06 19:27 麻雀虽小五脏俱全 阅读(3557) 评论(0) 推荐(1) 编辑
摘要: /** * Created by root * Description : Tuple and Map */ object MapTest { def main(args: Array[String]): Unit = { // 元组:Tuple,就是由()包起来,和数据库中一条记录概念类似 val t1 = (1,2) println(t1) ... 阅读全文
posted @ 2017-12-06 19:27 麻雀虽小五脏俱全 阅读(2642) 评论(0) 推荐(0) 编辑
摘要: // Stream:Stream is lazy List; // Stream惰性求值指它只确定第一个值,后面的值用到再求值,这样可以防止数据过大全部加载导致内存溢出 // 将Range转化成Stream val stream = (1 to 1000).toStream println(stream) // Stream(1, ?) println(strea... 阅读全文
posted @ 2017-12-06 19:24 麻雀虽小五脏俱全 阅读(2581) 评论(0) 推荐(0) 编辑
摘要: // Range:to:默认步进为1 val to1 = 1 to 10 println(to1) // 定义一个不进为2的Range val to2 = 1 to 10 by 2 println(to2) println(to2.toList) // Range:until val until1 = 1 until 10 println(until1)... 阅读全文
posted @ 2017-12-06 19:23 麻雀虽小五脏俱全 阅读(6613) 评论(1) 推荐(0) 编辑
摘要: /** * Created by root * Description : List */ object ListTest { def main(args: Array[String]): Unit = { println() } val a = List(1,2,3,4) for (i x % 2 ==0) println(e) // ... 阅读全文
posted @ 2017-12-06 19:22 麻雀虽小五脏俱全 阅读(13926) 评论(0) 推荐(0) 编辑
摘要: /** * Created by root * Description : 柯里化函数,偏应用函数,匿名函数,高阶函数 */ object FunctionTest { def main(args: Array[String]): Unit = { //柯里化函数 def add(x:Int)(y:Int):Int= x + y //等价 def add(x:... 阅读全文
posted @ 2017-12-06 14:09 麻雀虽小五脏俱全 阅读(308) 评论(0) 推荐(0) 编辑
摘要: /** * Created by root * Description : 递归函数 */ object RecursionTest { def main(args: Array[String]): Unit = { // a到b的累加 def foo(a:Int,b:Int):Int ={ if (a > b) 0 else a + f... 阅读全文
posted @ 2017-12-06 11:08 麻雀虽小五脏俱全 阅读(332) 评论(0) 推荐(0) 编辑
摘要: /** * Created by root * Description :CallByValue:进入函数就得先计算实参的值;CallByName:函数体重使用到的时候才计算 */ object CallByValueAndCallByName { def main(args: Array[String]): Unit = { val c = add(1+2,3) ... 阅读全文
posted @ 2017-12-06 11:07 麻雀虽小五脏俱全 阅读(664) 评论(0) 推荐(0) 编辑