logo
  • 教程列表
  • SO官方文档
  • 评估订单
    • ReplaceAll 和 ReplaceRepeated 的应用
    • 冒泡排序
  1. StackOverflow 文档
  2. wolfram-mathematica 教程
  3. 评估订单
  4. 冒泡排序

冒泡排序

Created: November-22, 2018

使用规则和替换进行冒泡排序:

list = {1, 4, 2, 3, 6, 7, 8, 0, 1, 2, 5, 4}

list //. {fsts___, x_, y_, lsts___} :> {fsts, y, x, lsts} /; y < x

(* 
    Out[1] := {1, 4, 2, 3, 6, 7, 8, 0, 1, 2, 5, 4}
    Out[1] := {0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 8}
*)
  • ReplaceAll 和 ReplaceRepeated 的应用

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明