FifoNodeStore.java in eightpuzzle.zip
Sponsored links
import java.util.LinkedList;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author samiQ
*/
public class FifoNodeStore implements NodeStore {
LinkedList<Node> queue;
public FifoNodeStore() {
queue = new LinkedList<Node>();
}
public void add(Node anItem) {
queue.add(anItem);
}
public Node remove() {
return queue.removeFirst();
}
public boolean isEmpty() {
return queue.isEmpty();
}
public int size() {
return queue.size();
}
public void insertAtHead(Node newNode){
LinkedList<Node> newQueue = new LinkedList<Node>();
newQueue.addFirst(newNode);
for(int i=0; i<queue.size(); i++){
newQueue.addLast(queue.get(i));
}
queue.clear();
queue.addAll(newQueue);
newQueue.clear();;
newQueue = null;
}
// insert node in between 2
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.