import java.util.*;
// write a queue class that will let you print out class
// also lets you remove an object from queue
// note : because of extra functions this is not a real queue
class queue2
{
private Queue myQueue= new LinkedList();
public boolean add(String x)
{myQueue.add(x);
return true;
}
public void remove(String x)
{Queue q3 = new LinkedList();
String s;
while (! myQueue.isEmpty())
{s = myQueue.remove();
if (! s.equals(x))
q3.add(s); // removes all occurences of String x
}
myQueue = q3;
}
public void print()
{Queue q3 = new LinkedList();
while (! myQueue.isEmpty())
{String s = myQueue.remove();
System.out.println(s);
q3.add(s);
}
myQueue = q3;
}
}
__________________________________________________________
import java.io.*;
class queueDriver
{public static input in = new input();
public static void main(String[] args) throws IOException
{queue2 q = new queue2();
q.add("Joe");
q.add("Tom");
q.add("Helen");
q.add("Sarah");
q.print();
System.out.println();
System.out.println();
System.out.println();
q.remove("Helen");
q.print();
}
}