1、产生随机序
def RandomList(n: Int) = Seq.fill(n)(scala.util.Random.nextInt(n))
def RandomDiffList(n: Int): List[Int] = {
var resultList: List[Int] = Nil
while (resultList.length < n) {
val tempNum = (new scala.util.Random).nextInt(n)
if (!resultList.contains(tempNum))
resultList = resultList ::: List(tempNum)
}
resultList
}
2、排序算法
1)希尔排序
def shellSort(SortList: List[Int]): List[Int] = {
val cpSortList = SortList.toArray
var d = cpSortList.length
while (d > 1) {
d = math.floor(d / 2).toInt
for (i <- 0 to d) {
for (j <- Range(i, cpSortList.length, d)) {
var minIndex = j;
for (o <- Range(j + d, cpSortList.length, d)) {
if (cpSortList(minIndex) > cpSortList(o))
minIndex = o
}