המחלקה תור
public class Queue <T> {
private Node<T> first;
private Node<T> last;
public Queue(){
this.first = null;
this.last = null;
}
public void insert (T x){
Node <T> tmp = new Node<T>(x);
if (first == null){
first = tmp;
}
else{
last.setNext(tmp);
}
last = tmp;
}
public T remove(){
T x = first.getValue();
first = first.getNext();
if (first == null)
last = null;
return x;
}
public T head(){
return first.getValue();
}
public boolean isEmpty(){
return (first == null);
}
}
עמוד 151
תרגילים 1-10 כאשר 6-10 חובה !!!