package heap;
public class Queue{
class QNode{
int data;
QNode next;
}
protected QNode first;
protected QNode last;
public Queue(){
first = null;
last = null;
}
public int first(){
return first.data;
}
public boolean empty(){
return (first == null);
}
public void add(int o){
QNode aux = new QNode();
aux.data = o;
aux.next = null;
if (empty()){
first = aux;
last = aux;
} else{
last.next = aux;
last = aux;
}
}
public Queue copy(){
Queue out = new Queue();
if (first != null){
QNode aux = new QNode();
out.first = aux;
aux.data = first.data; //.copy();
QNode pointer = first.next;
while (pointer != null){
aux.next = new QNode();
aux = aux.next;
aux.data = pointer.data;//.copy();
pointer = pointer.next;
}
out.last = aux;
}//if !empty
return out;
}
/*
public String print(){
String out = "[";
QNode aux = first;
while (aux != null){
out += aux.data.print();
out += ",";
aux = aux.next;
}
out += "]";
return out;
}
*/
/*
public static void main(String[] args){
Queue q = new Queue();
Queue q2 = q.copy();
q.add(new Test1(1,null));
q2 = q.copy();
q.add(new Test1(2,null));
q2 = q.copy();
q.add(new Test1(3,null));
q.add(new Test1(4,null));
q2.add(new Test1(10,null));
System.out.println(q.print());
System.out.println(q2.print());
}
*/
}
|