1. 程式人生 > >(一)隊列操作

(一)隊列操作

次數 int out sys print pre ++ ray 移動

情景,給定一個數組,從頭開始遍歷,第一位的元素輸出,下一位移動到隊尾,直到所有元素輸出,

換一種表達方式就是偶數位的元素輸出,奇數位的元素移動到隊尾。

插入次數

1 x + n = 2x
2 x = n 

 1 package algorithm;
 2 
 3 public class Algorithm1 {
 4     public static void main(String[] args) {
 5         int[] nums = {8, 9, 0, 3, 4, 5, 21, 5, 3, 234};
 6         int head = 0, tail = nums.length - 1, n = nums.length;
7 int[] nums2 = new int[n + n]; 8 System.arraycopy(nums, 0, nums2, 0, n); 9 while (head <= tail) { 10 System.out.println(nums2[head++]); 11 nums2[++tail] = nums2[head++]; 12 } 13 } 14 }

(一)隊列操作