Rhyme/Java自定义队列
来源:互联网 发布:淘宝静物相机 编辑:程序博客网 时间:2024/06/05 20:42
Java自定义队列
package com.maple.myqueue;import java.util.Arrays;/** * the implements of my queue * @author RhymeChiang * @date 2017/12/04 **/public class MyQueue { /** * the size of currrnt */ private int size; private int capacity=3; /** * the container */ private int data[]=new int[capacity]; /** * the first point */ private int first; /** * the end point */ private int end; /** * append a data into my queue * @param a */ public void append(int a){ data[size]=a; size++; // expand the capacity if(size==data.length-1){ capacity=capacity*2; int newData[] = new int[capacity]; for(int i = 0;i<size;i++){ newData[i]=data[i]; } data = newData; } } /** * pop up the top element of this queue * @return */ public int popUp(){ int top = data[0]; for(int i=0;i<size;i++){ data[i]=data[i+1]; } size--; return top; } public int[] getData() { return data; } public void setData(int[] data) { this.data = data; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } public static void main(String[] args) { MyQueue queue = new MyQueue(); queue.append(1); queue.append(2); queue.append(3); queue.append(4); queue.append(5); System.out.println("pop ele: "+queue.popUp()); System.out.print("the elements in the queue:"); for(int i=0;i<queue.getSize();i++){ System.out.print(queue.getData()[i]+" "); } }}
测试结果
阅读全文
0 0
- Rhyme/Java自定义队列
- java自定义队列
- Rhyme/插入排序Java版
- Rhyme/归并排序Java版
- java 阻塞队列自定义实现
- Java自定义实现链队列
- Rhyme/Java 泛型<T>很详细教程
- Rhyme/ Java IO流关闭工具类
- Rhyme/Java 常用IO流总结
- Rhyme/Java 适配器模式应用场景
- Rhyme/Quick Sort 快速排序Java版
- Rhyme/Java 打印递归堆栈轨迹
- Rhyme/Java 设计模式之工厂模式
- Rhyme/二分查找(binary search)Java版
- Rhyme/冥运算(分治策略)Java版
- 阻塞队列自定义实现 in Java
- 阻塞队列自定义实现 in Java
- Java 自定义 线程池与任务队列
- wait()函数,自杀函数abort(),WIFEXITED WIFSIGNALED
- Vue新手入门-1
- Sprites,Editor使图片生成prefab
- 数据库Oracle 数据导入/导出说明
- python any()和all()用法
- Rhyme/Java自定义队列
- 大整数加法(函数)
- java 接口和抽象类的几点区别
- Ubuntu 16.04 上安装 CUDA 9.0 详细教程
- HTML学习笔记(一)
- js中Object对象常用方法和属性
- java基础-九九乘法表
- spring的DI配合接口编程
- 吴恩达(Andrew Ng)深度学习工程师笔记