【发布时间】:2015-11-22 18:46:00
【问题描述】:
我的作业有点麻烦;我的任务是想出自己的解决方案来解决煎饼问题。
我已经把大部分代码都写下来了,除了这一部分(以下是伪代码):
//assuming input is an array of [0...n-1] size
int maxValue = -infinity
for int i <- 0 to n-1 do
{
for int j <-i to n-1 do
{
if A[j] > maxValue
{
maxValue <- A[j]
maxPos <- j
if ((maxPos == n-1) && (maxPos > i))
{
flip(i) //flipping starting from index i
}
/*the following is the bit i'm stuck on
i know that should be able to flip the max value IN the array
(but not the end) to the n-1 term.
On the next iteration of the loop, i flip the maxValue (now held in the last
element) into the slot that is either at the beginning of the array, or at the
element closest to the elements already sorted */
maxValue <- -infinity
抱歉,对于随机短代码,我在输入 =(.
时过早按下了 sumbit【问题讨论】:
-
什么是 maxValue? n的值是多少?
-
N 是数组中的项目数。 MaxValue 是该特定迭代的数组中的最大值