ai-22 / src / am / aua / search / DepthFirstFrontier.java
DepthFirstFrontier.java
Raw
package am.aua.search;

import java.util.Deque;
import java.util.LinkedList;

public class DepthFirstFrontier implements Frontier {
    Deque<Node> frontier;

    // statistics
    private int stretchFactor;

    public DepthFirstFrontier() {
        frontier = new LinkedList<>();
        stretchFactor = 0;
    }

    @Override
    public void add(Node node) {
        frontier.push(node);
        stretchFactor = Math.max(stretchFactor, frontier.size());
    }

    @Override
    public Node remove() {
        return frontier.pop();
    }

    @Override
    public void clear() {
        frontier.clear();
    }

    @Override
    public boolean isEmpty() {
        return frontier.isEmpty();
    }

    @Override
    public int stretchFactor() {
        return stretchFactor;
    }

    @Override
    public String toString() {
        return "Depth First";
    }
}