Java Queue

개발자/Java 2015. 7. 1. 14:20

package queue;


public class Queue {


private int front;

private int rear;

private String[] dataAr;

private final int arrayMax = 10;

public Queue() {

// TODO Auto-generated constructor stub

dataAr = new String[arrayMax];

put("push1");

peek();

get();

put("push2");

peek();

get();

put("push3");

peek();

get();

put("push4");

peek();

get();

get();

get();

put("push5");

peek();

}

private boolean empty() {

// TODO Auto-generated method stub

if(front == rear){

System.out.println("비었을 경우 = Underflow");

return true;

}

return false;

}

//front 데이터 출력

private void peek() {

// TODO Auto-generated method stub

System.out.println("peek() : " +  dataAr[front] + "front : " + front + " rear : " + rear);

}


private void put(String temp) {

// TODO Auto-generated method stub

dataAr[rear] = temp;

rear++;

}

private void get() {

// TODO Auto-generated method stub

if(!empty()){

String get = dataAr[front];

System.out.println("삭제  : " + get);

front++;

}

}


}



블로그 이미지

김진리

,