
这里我们将看到另一个排序问题,名为煎饼排序。这个问题很简单。我们有一个数组。我们必须对此进行排序。但我们只能使用一种称为 rev(arr, i) 的操作。这会将 arr 的元素从 0 反转到第 i 个位置。
这个想法就像选择排序。我们反复将最大元素放在末尾,以减少数组的大小。让我们看看算法来理解这个想法。
在原版的基础上做了一下修正评论没有提交正文的问题特价商品的调用连接问题去掉了一个后门补了SQL注入补了一个过滤漏洞浮动价不能删除的问题不能够搜索问题收藏时放入购物车时出错点放入购物车弹出2个窗口修正主题添加问题商家注册页导航连接问题销售排行不能显示更多问题热点商品不能显示更多问题增加了服务器探测 增加了空间使用查看 增加了在线文件编辑增加了后台管理里两处全选功能更新说明:后台的部分功能已经改过前台
算法
pancakeSort(arr, n)
Begin
size := n
while size > 1, do
index := index of max element in arr from [0 to size – 1]
rev(arr, index)
rev(arr, size - 1)
size := size - 1
done
End示例
#includeusing namespace std; void rev(int arr[], int i) { int temp, st = 0; while (st < i) { temp = arr[st]; arr[st] = arr[i]; arr[i] = temp; st++; i--; } } int maxIndex(int arr[], int n) { int index, i; for (index = 0, i = 0; i < n; ++i){ if (arr[i] > arr[index]) { index = i; } } return index; } int pancakeSort(int arr[], int n) { for (int size = n; size > 1; size--) { int index = maxIndex(arr, size); if (index != size-1) { rev(arr, index); rev(arr, size-1); } } } int main() { int arr[] = {54, 85, 52, 25, 98, 75, 25, 11, 68}; int n = sizeof(arr)/sizeof(arr[0]); pancakeSort(arr, n); cout << "Sorted array: "; for (int i = 0; i < n; ++i) cout << arr[i] << " "; }
输出
Sorted array: 11 25 25 52 54 68 75 85 98









