码迷,mamicode.com
首页 > 其他好文 > 详细

(一)队列操作

时间:2019-02-08 11:52:19      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:个数   输出   out   元素   sys   head   algo   public   string   

情景,给定一个数组,从头开始遍历,第一位的元素输出,下一位移动到队尾,直到所有元素输出,

换一种表达方式就是偶数位的元素输出,奇数位的元素移动到队尾。

插入次数

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 }

 

(一)队列操作

标签:个数   输出   out   元素   sys   head   algo   public   string   

原文地址:https://www.cnblogs.com/ylxn/p/10355948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!