scala实现相邻两个元素挑换位置的代码,哈哈
2018-01-30 15:01
302 查看
import scala.math._ import breeze.plot._ import breeze.linalg._ import scala.collection.mutable.ArrayBuffer //https://stackoverflow.com/questions/36984780/spark-shell-how-to-use-breeze-viz object breeze2 { def main(args: Array[String]): Unit = { } def pow(x: Double, n: Int): Double = { var pw = 1.0.toDouble var i = 1 var m = n for (j <- 1 to (m / 2) if n % 2 == 0 && x > 0) { pw *= x } for (j <- 1 to m if n % 2 == 1 && x > 0) { pw *= x } for (j <- 1 to m if x < 0) { pw *= 1 / x } pw } // println(pow(3, 4)) val b = ArrayBuffer(1, 7, 2, 9) val bSorted = b.sorted val a = ArrayBuffer(2,3,4,5,6,7) val i=0 for(i<-0 until a.length) { for(j<-1 until a.length if (i==j-1) if(i%2==0)) { val temp=a(i) a(i)=a(j) a(j)=temp } } for(t<- a) { println(a) } }
相关文章推荐
- (***)有两个10个元素的数组,分别为A和B,编程实现相同位置的元素, 如果 B 的元素小于 A 的元素进行数值交换:(使用回调函数实现)
- C语言双向链表实现根据使用频率安排元素位置的功能实例代码
- 有两个10个元素的数组,分别为A和B,编程实现相同位置的元素, 如果 B 的元素小于 A 的元素进行数值交换:(使用回调函数实现)
- 剑指offer 01-06解答思路以及代码(顺序数组找特定数字,替换空格字符,链表反转输出,重建二叉树,两个栈实现队列效果,旋转数组最小元素)
- 使用jQuery实现两个div中按钮互换位置的实例代码
- js从数组中删除指定值(不是指定位置)的元素实现代码
- FF火狐下获取一个元素同类型的相邻元素实现代码
- 两个升序表,打印L中那些由P所指定的位置上的元素 java实现
- 用Scala实现集合中相邻元素间的差值
- 一行代码实现对列表a中的偶数位置的元素进行加3后求和(阿里校招)
- js数组特定位置元素置空,非null和undefined,实现echarts现状图效果;谷歌格式化压缩js代码
- 数组A中任意两个相邻元素大小相差1,现给定这样的数组A和目标整数t,找出t在数组A中的位置。
- 第一次发博客,新手初试啊,题目如下:有两个10个元素的数组,分别为A和B,编程实现相同位置的元素, 如果 B 的元素小于 A 的元素进行数值交换:(使用回调函数实现)
- A的大小为n,其中的每相邻的两个元素之间差的绝对值为1,例如A={4 5 6 5 6 7 8 9 10 9},给定A和t,设计一个程序,求出t在A中的位置
- js获取元素相对窗口位置的实现代码
- 删除两个升序正数组中重复元素的C程序实现代码
- js获取元素相对窗口位置的实现代码
- 链表的基本操作(创建,查找指定位置元素,删除指定元素,插入,倒置,去重,求集合的差,分别交换结点与交换结点值实现的冒泡排序,将两个有序链表合并成一个有序链表)c语言实现
- 【面试题】-数组A中任意两个相邻元素大小相差1,找出某个数在数组A中的位置。(所有位置 )