kotlin MutableList sort
fun MutableList<Int>.swap(index1: Int, index2: Int) {
val tmp = this[index1] // 'this' corresponds to the list
this[index1] = this[index2]
this[index2] = tmp
}
fun main(args: Array<String>) {
val l = mutableListOf(1, 2, 3,9,60,54,8,21)
l.forEachIndexed {index, value ->run{
l.forEachIndexed { index, value ->
run{
if(((index+1)<l.size) && (l[index+1]>=l[index])){
// println(""+l[index+1]+">"+""+l[index])
l.swap(index,index+1)
}
}
}
}}
println("--------------------")
for(t in l.indices){println(l[t])}
println("--------------------")
}
kotlin MutableList sort的更多相关文章
- Kotlin for Java Developers 学习笔记
Kotlin for Java Developers 学习笔记 ★ Coursera 课程 Kotlin for Java Developers(由 JetBrains 提供)的学习笔记 " ...
- 函数式Android编程(II):Kotlin语言的集合操作
原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...
- Kotlin 介绍
Kotlin (0:00) 大家好,我是 Michael Pardo,今天我要给大家展示一下 Kotlin 这门语言,同时看看他如何让你在 Android 开发的时候更开心,更有效率. Kotlin ...
- Kotlin入门第二课:集合操作
测试项目Github地址: KotlinForJava 前文传送: Kotlin入门第一课:从对比Java开始 初次尝试用Kotlin实现Android项目 1. 介绍 作为Kotlin入门的第二课, ...
- Kotlin入门(16)容器的遍历方式
Kotlin号称全面兼容Java,于是乎Java的容器类仍可在Kotlin中正常使用,包括大家熟悉的队列ArrayList.映射HashMap等等.不过Kotlin作为一门全新的语言,肯定还是要有自己 ...
- 【Try Kotlin】Kotlin Koans 代码笔记
Kotlin Koans 心印 Introduction 1.Hello, world! Simple Functions Take a look at function syntax and mak ...
- 初识Kotlin之集合
Kotlin的集合是让我为之心动的地方,丰富的高阶函数帮助我们高效开发.今天介绍Kotlin的基础集合用法.获取集合元素的函数.过滤元素的函数.元素排序的函数.元素统计的函数.集合元素映射的函数.集合 ...
- 用Kotlin语言重新编写Plaid APP:经验教训(I)
原文标题:Converting Plaid to Kotlin: Lessons learned (Part 1) 原文链接:http://antonioleiva.com/plaid-kotlin- ...
- Kotlin实现LeetCode算法题之Median of Two Sorted Arrays
题目Median of Two Sorted Arrays(难度Hard) 方案1,数组合并&排序调用Java方法 import java.util.* class Solution { fu ...
随机推荐
- Asp.net button防止点击多次数据提交
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat= ...
- Android圆形图片--自己定义控件
Android圆形图片控件效果图例如以下: 代码例如以下: RoundImageView.java package com.dxd.roundimageview; import android.con ...
- zzuoj--10401--物资调度(dfs)
A.物资调度 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 93 Solved: 52 [Submit][Status][Web Board] De ...
- 关于webuploader跨域解决方法
1.在iis处理程序映射 2.后台ashx处理添加如下代码
- POJ 3320 Jessica's Reading Problem (尺取法,时间复杂度O(n logn))
题目: 解法:定义左索引和右索引 1.先让右索引往右移,直到得到所有知识点为止: 2.然后让左索引向右移,直到刚刚能够得到所有知识点: 3.用右索引减去左索引更新答案,因为这是满足要求的子串. 4.不 ...
- 【原创】ApacheTomcat集群在Linux下的搭建步骤
在RedHat5(以下简称RH)上搭建ApacheTomcat的集群环境,有以下步骤: 1.首先安装apr和apr-util apr-util需要依赖于apr包,所以先安装apr, http://fi ...
- SpringMVC-注解映射器和适配器_20190323
1 注解映射器和适配器 1.1 注解映射器spring3.1之前默认加载映射器是org.springframework.web.servlet.mvc.annotation.DefaultAnnota ...
- First-class citizen
In programming language design, a first-class citizen (also type, object, entity, or value) in a giv ...
- Site Isolation Design Document
This design document covers technical information about how Site Isolation is built. For a general ...
- [国家集训队]最长双回文串 (PAM)回文自动机
Code: // luogu-judger-enable-o2 #include <cstdio> #include <algorithm> #include <cstr ...