在一个通行证中移动所有元素
我试图弄清楚如何在java中逐渐增加一个值,而无需使用第二个数组来存储值。有没有办法一次在内存中只有几个(1-3ish)的值并转移一切?
I'm trying to figure out how to do a value shift in an array by one value incrementally in Java, without using a second array to store values. Is there a way to just have a couple (1-3ish) of values in memory at a time and shift over everything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在单个通行证中移动所有内容实际上是气泡弹头的单个迭代。
,但是,如果它对您有用,我建议您在Java阵列周围包装器,您将存储其他参数 - >
shift
。通过这样的实现,您将在阵列读取/写操作中实现巨大的效率,而代码消费者将无法弄清楚差异。问题在于
使用方法
shift()
在“实时”中计算位置/索引:下面:To shift everything in a single pass is actually a single iteration of bubble-sort.
But, if it works for you, I would recommend the wrapper around java array where you will store additional parameter ->
shift
. With such an implementation, you would achieve great efficiency in array read/write operation and code consumers will not figure out the difference.The thing is in calculation of the position/index in "real time"
Full code with method
shift()
is below: