package algorithm.queue;
public class Queue {
private Node head = null;
private Node tail = head;
private int size = 0;
public void enQueue(int number) {
Node queue = new Node();
queue.number = number;
if (head == null) {
head = queue;
tail = head;
} else {
tail.next = queue;
tail = queue;
}
size++;
}
public int deQueue() throws QueueException {
if (!isEmpty()) {
int temp = head.number;
head = head.next;
size--;
return temp;
}else{
throw new QueueException("no data.size is 0");
}
}
public boolean isEmpty() {
if (size == 0) {
return true;
} else {
return false;
}
}
public int size(){
return this.size;
}
}
-----------------
package algorithm.queue;
public class Node {
int number;
Node next = null;
}
'ALGORITHM' 카테고리의 다른 글
BUBBLE SORT (0) | 2011.04.14 |
---|---|
BINARY TREE (0) | 2011.04.12 |
각 algorithm의 node는 직접 만들어 볼것. (0) | 2011.04.08 |
STACK (0) | 2011.04.08 |
LINKEDLIST (0) | 2011.04.07 |