【发布时间】:2012-04-14 08:22:00
【问题描述】:
- 实现一个检查数组并返回 0 或 1 的函数, 其中 0 表示数组未排序,1 表示数组未排序 已排序。
- 如果数组未排序,则执行选择排序以删除 在排序过程中重复。
【问题讨论】:
-
你尝试了什么?是作业吗?如果是 - 请这样标记。
-
这是你的家庭作业吗?如果是这样,至少尝试自己做......
【问题讨论】:
第 1 点应该很简单:
loop through the whole array
{
if (array[THIS INDEX] > array[THIS INDEX + 1]) //the element before is greater than the next one
ARRAY IS NOT SORTED
}
//IF LOOP IS COMPLETED AND CODE REACHES THIS POINT
ARRAY IS SORTED
【讨论】:
This lets potential answerers know that they SHOULD guide the student in solving the problem, and SHOULD NOT simply show the complete answer.
i
[0,array.length) 表达式 array[i] <= array[i+1] 的结果为真(确保您理解为什么这个约束很重要)。【讨论】: