[오라클자바커뮤니티,자바교육강좌,자바학원,JAVA]자바큐,JAVA QUEUE,자바 배열로 만든 큐(Java Array Queue), 자바배열큐,JAVA ARRAY QUEUE
import java.io.*;
interface Queue1 {
public boolean isEmpty();
public boolean isFull();
public Object getFrontEelement();
public Object getRearEelement();
public void put(Object theObject);
public Object remove();
}
public boolean isEmpty();
public boolean isFull();
public Object getFrontEelement();
public Object getRearEelement();
public void put(Object theObject);
public Object remove();
}
class QueueManager implements Queue1 {
final static int MAXQUEUE=100;
private Object[] queue;
private int front;
private int rear;
final static int MAXQUEUE=100;
private Object[] queue;
private int front;
private int rear;
public QueueManager() {
queue = new Object[MAXQUEUE];
front = 0;
rear = -1;
}
queue = new Object[MAXQUEUE];
front = 0;
rear = -1;
}
public boolean isEmpty() {
return front > rear;
}
return front > rear;
}
public boolean isFull() {
return rear == MAXQUEUE-1;
}
return rear == MAXQUEUE-1;
}
public void put(Object theObject) {
if (isFull()) {
System.out.println("Queue가 꽉 찼습니다...");
return;
}
queue[++rear] = theObject;
}
if (isFull()) {
System.out.println("Queue가 꽉 찼습니다...");
return;
}
queue[++rear] = theObject;
}
public Object remove() {
if (isEmpty()) {
System.out.println("Queue가 공백 입니다...");
return null;
}
Object item = queue[front];
front++;
return item;
}
if (isEmpty()) {
System.out.println("Queue가 공백 입니다...");
return null;
}
Object item = queue[front];
front++;
return item;
}
public Object getFrontEelement() {
return queue[front];
}
return queue[front];
}
public Object getRearEelement() {
return queue[rear];
}
return queue[rear];
}
public void pointerPrint() {
System.out.println("F : " + front + " , R: " + rear);
}
}
System.out.println("F : " + front + " , R: " + rear);
}
}
public class QueueTest {
public static void main(String[] args) {
QueueManager q = new QueueManager();
q.put(new String("aaaa"));
q.put(new String("bbbb"));
q.put(new String("cccc"));
System.out.println("a,b,c 삽입후...");
q.pointerPrint();
public static void main(String[] args) {
QueueManager q = new QueueManager();
q.put(new String("aaaa"));
q.put(new String("bbbb"));
q.put(new String("cccc"));
System.out.println("a,b,c 삽입후...");
q.pointerPrint();
q.remove();
System.out.println("aaaa 삭제후...");
System.out.println("front : " + q.getFrontEelement());
System.out.println("rear : " + q.getRearEelement());
q.pointerPrint();
}
}
System.out.println("aaaa 삭제후...");
System.out.println("front : " + q.getFrontEelement());
System.out.println("rear : " + q.getRearEelement());
q.pointerPrint();
}
}
댓글 없음:
댓글 쓰기