C ++编写shuffle函数来改组数组 - 练习 [英] C++ Write shuffle function to shuffle an array - exercise

查看:105
本文介绍了C ++编写shuffle函数来改组数组 - 练习的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个shuffle函数来对具有偶数个元素的排序数组进行混洗,但它不会打印出前两个元素,如下所示。

当我打印temp []数组时,它也只打印前两个元素。所以我认为循环是在2次迭代后停止。

任何人都可以看到我的错误吗?

I`m trying to write a shuffle function to shuffle a sorted array with an even number of elements but it won`t print past the first 2 elements as shown below.
When i print the temp[] array it only prints the first 2 elements also. So i presume the loop is is stopping after 2 iterations.
Can anyone see my error?.

展开 | 选择 < span class =codeDivider> | Wrap | 行号

推荐答案

好的,我会在这里回到你的算法,我不完全确定你是以什么为基础洗牌。


洗牌的目标是什么?您是否尝试随机分配这些值,或者以特定方式(即,在特定算法之后)进行排序?或者我完全错过了你的问题?
Okay, I''d go back to your algorithm here, I''m not entirely sure on what basis you are "shuffling".

What is the goal of a shuffle? Are you trying to get those values randomly assorted, or sorted in a specific fashion (ie, after a specific algorithm)? Or did I just totally miss your question?


它意味着在四个较高值之间交错较低值元素,如下所示它应该是。
Its meant to interleave the lower value elements between the four higher value ones as shown below "it should be".


好的,所以看起来你想到了这种转变的数学表示?我看到第一个停留在它的位置,第二个移动一个位置,第三个移动两个位置,第四个移动三个位置...
Okay, so it looks like you had in mind a mathematical representation of the shift? I''m seeing that the first one stays in its place, the second moves one places up, the third moves two places up, and the fourth moves three places up...


这篇关于C ++编写shuffle函数来改组数组 - 练习的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆