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++;
}
}
}
'개발자 > Java' 카테고리의 다른 글
Java Stack (0) | 2015.07.01 |
---|---|
jasperreports: Font '바탕' is not available to the JVM. See the Javadoc for more details. (4) | 2014.12.09 |
원하는 일수만큼 입력받아서 현재날짜로부터 이전날짜를 구하기 (0) | 2014.06.23 |
java.lang.NoClassDefFoundError : <wrong name : > (0) | 2014.01.28 |
자바 슈팅 게임 2단계 (2) | 2013.12.08 |