package com.maple.myqueue;
import java.util.Arrays;
/**
* the implements of my queue
* @author RhymeChiang
* @date 2017/12/04
**/publicclassMyQueue {/**
* the size of currrnt
*/privateint size;
privateint capacity=3;
/**
* the container
*/privateint data[]=newint[capacity];
/**
* the first point
*/privateint first;
/**
* the end point
*/privateint end;
/**
* append a data into my queue
* @param a
*/publicvoidappend(int a){
data[size]=a;
size++;
// expand the capacityif(size==data.length-1){
capacity=capacity*2;
int newData[] = newint[capacity];
for(int i = 0;i<size;i++){
newData[i]=data[i];
}
data = newData;
}
}
/**
* pop up the top element of this queue
* @return
*/publicintpopUp(){
int top = data[0];
for(int i=0;i<size;i++){
data[i]=data[i+1];
}
size--;
return top;
}
publicint[] getData() {
return data;
}
publicvoidsetData(int[] data) {
this.data = data;
}
publicintgetSize() {
return size;
}
publicvoidsetSize(int size) {
this.size = size;
}
publicstaticvoidmain(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]+" ");
}
}
}