zoukankan      html  css  js  c++  java
  • List的一阶函数操作代码实战详解之Scala学习笔记-25

    package com.leegh.dataset

    /**
    * @author Guohui Li
    */
    object MergedSort {

    def main(args: Array[String]): Unit = {
    def mergedsort[T](less: (T, T) => Boolean)(input: List[T]): List[T] = {
    def merge(xList: List[T], yList: List[T]): List[T] =
    (xList, yList) match {
    case (Nil, _) => yList
    case (_, Nil) => xList
    case (x :: xtail, y :: ytail) =>
    if (less(x, y)) x :: merge(xtail, yList)
    else y :: merge(xList, ytail)
    }
    val n = input.length / 2
    if (n == 0) input
    else {
    val (x, y) = input splitAt n
    merge(mergedsort(less)(x), mergedsort(less)(y))
    }
    }
    println(mergedsort((x: Int, y: Int) => x < y)(List(3, 7, 9, 5)))
    val reversed_mergedsort = mergedsort((x: Int, y: Int) => x > y)_
    println(reversed_mergedsort(List(3, 7, 9, 5)))
    }

    }

    附:

    本博客说明:

    1.整理思路,提高自己。

    2.受教于王家林老师,​有所收获,故推荐。

    3.博客注重实践,多余的文字就不多说了,都是做技术的。

    4.信息来源于 DT大数据梦工厂微信公众账号:DT_Spark。​

    DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。

    Scala 深入浅出实战经典(1-64讲)完整视频、PPT、代码下载:

    百度云盘:http://pan.baidu.com/s/1c0noOt6
    腾讯微云:http://url.cn/TnGbdC
    360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2


    DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。

  • 相关阅读:
    Windows 8实例教程系列 开篇
    qt 开发发布于 windeploy.exe
    qt qoci 测试验证
    vmware vmx 版本不兼容
    qt oracle
    vc qt dll
    QOCIDriver unable to create environment
    qoci 编译完 放置位置 具体根据情况
    calling 'lastError' with incomplete return type 'QSqlError' qsqlquer
    Hbase 操作工具类
  • 原文地址:https://www.cnblogs.com/leegh1992/p/4738325.html
Copyright © 2011-2022 走看看