【问题标题】:cycle-sort : why the outer most loop runs (n-1) times循环排序:为什么最外面的循环运行(n-1)次
【发布时间】:2017-07-19 15:13:57
【问题描述】:

我正在学习循环排序,并且对为什么循环排序的外循环运行 (n-1) 次而不是 n 次感到困惑。(n 是数组大小)

 for (int cycle_start=0; cycle_start< n-1; cycle_start++)

请解释一下。谢谢

【问题讨论】:

    标签: sorting cycle-sort


    【解决方案1】:

    在循环排序中,最后一项将自动位于正确的位置,因此您无需循环遍历它。

    【讨论】:

      猜你喜欢
      • 2020-07-22
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多