forked from IF-LK-2020/queue-stack
enqueue and dequeue implemented
This commit is contained in:
16
Queue.java
16
Queue.java
@@ -9,11 +9,23 @@ public class Queue<ContentType> {
|
||||
}
|
||||
|
||||
public void enqueue( ContentType pContentObject ) {
|
||||
// TODO: Implementiere enqueue
|
||||
if (head == null) {
|
||||
head = new QueueNode<ContentType>(pContentObject);
|
||||
tail = head;
|
||||
} else {
|
||||
QueueNode<ContentType> node = new QueueNode<ContentType>(pContentObject);
|
||||
tail.setNext(node);
|
||||
tail = node;
|
||||
}
|
||||
}
|
||||
|
||||
public void dequeue() {
|
||||
// TODO: Implementiere dequeue
|
||||
if (head != tail) {
|
||||
head = head.getNext();
|
||||
} else if (head != null) {
|
||||
head = null;
|
||||
tail = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user