1. 구현 기능
2. 구현 코드
public class MyListQueue {
public MyListNode front;
public MyListNode rear;
MyLinkedList listQ;
public int count;
public MyListQueue() {
listQ = new MyLinkedList();
front = null;
rear = null;
}
public void enQueue(String data) {
MyListNode newNode = listQ.addNode(data);
if (isEmpty()) {
front = newNode;
rear = newNode;
}
else {
rear.next = newNode;
rear = newNode;
}
count++;
}
public String deQueue() {
if (isEmpty()) {
System.out.println("요소 없음!");
return null;
}
else {
String data;
data = front.getData();
front = front.next;
count--;
return data;
}
}
public void printAll() {
MyListNode tempNode = front;
while(tempNode != null) {
System.out.println(tempNode.getData());
tempNode = tempNode.next;
}
}
public String getElement(int pos) {
return listQ.getElement(pos);
}
public boolean isEmpty() {
if(count == 0) {
return true;
}
else {
return false;
}
}
}