情景, 给定一个数组, 从头开始遍历, 第一位的元素输出, 下一位移动到队尾, 直到所有元素输出,
换一种表达方式就是偶数位的元素输出, 奇数位的元素移动到队尾.
插入次数
- x + n = 2x
- x = n
- package algorithm;
- public class Algorithm1 {
- public static void main(String[] args) {
- int[] nums = {8, 9, 0, 3, 4, 5, 21, 5, 3, 234};
- int head = 0, tail = nums.length - 1, n = nums.length;
- int[] nums2 = new int[n + n];
- System.arraycopy(nums, 0, nums2, 0, n);
- while (head <= tail) {
- System.out.println(nums2[head++]);
- nums2[++tail] = nums2[head++];
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2947328.html