swift排序演算法和資料結構

來源:互聯網
上載者:User

標籤:swift   資料結構   排序演算法   冒泡排序   

var arrayNumber: [Int] = [2,4, 6, 7, 3, 8, 1]

//冒泡排序

func maopao(var array: [Int]) -> [Int] {

   for var i = 0;i < array.count;i++ {

       for var j = i;j < array.count;j++ {

           if array[j] > array[j +1] {

               var temp = array[j]

                array[j] = array[j+1]

                array[j+1] = temp

            }

        }

    }

   return array

}

let array2 =maopao([2,4, 6, 7, 3, 8, 9, 5])

//待續。。。

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

swift排序演算法和資料結構

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.