자바 배열로 만든 큐(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();
}
}
<li tabindex="0" class="ui-state-default ui-corner-top ui-tabs-active ui-state-active" role="tab" aria-selected="true" aria-controls="tabs-1" aria-labelledby="ui-id-1">JAVA</li> <li tabindex="-1" class="ui-state-default ui-corner-top" role="tab" aria-selected="false" aria-controls="tabs-2" aria-labelledby="ui-id-2">ORACLE</li> <li tabindex="-1" class="ui-state-default ui-corner-top" role="tab" aria-selected="false" aria-controls="tabs-3" aria-labelledby="ui-id-3">iPhone/Android</li> <li tabindex="-1" class="ui-state-default ui-corner-top" role="tab" aria-selected="false" aria-controls="tabs-4" aria-labelledby="ui-id-4">.NET</li> <li tabindex="-1" class="ui-state-default ui-corner-top" role="tab" aria-selected="false" aria-controls="tabs-5" aria-labelledby="ui-id-5">표준웹/HTML5</li> <li tabindex="-1" class="ui-state-default ui-corner-top" role="tab" aria-selected="false" aria-controls="tabs-6" aria-labelledby="ui-id-6">채용/취업무료교육</li> <li tabindex="-1" class="ui-state-default ui-corner-top" role="tab" aria-selected="false" aria-controls="tabs-7" aria-labelledby="ui-id-7">초보자(재학생)코스</li>
댓글 없음:
댓글 쓰기