So, I started this problem where I have to bring a cabbage, wolf, and goat across the river without leaving the cabbage with the goat or the wolf and goat by themselves on the same side.
I started and got sorely confused about how to approach this. Basically I was thinking of adding a bunch of vertexes that would lead to the correct outcome, and just have the program demonstrate breadth-first and depth-first searching without having a complex vertices generation process. Am I thinking about this correctly, or is there a better approach?
Here is my code for the main method so far.
package project3;
import java.util.*;
import java.io.*;
public class Project3 extends Network{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Project3().run();
} //main method
public void run()
{
String start ="fwgcR",
finish = "Rfwgc";
addVertex(start);
addVertex("fwgRc");
addVertex("fwcRg");
addVertex(finish);
//Breadth First iterator
Iterator<String> itr = network.breadthFirstIterator (start);
while (itr.hasNext())
System.out.print (itr.next() + " ");
//Depth First Iterator
itr = network.depthFirstIterator (start);
while (itr.hasNext())
System.out.print (itr.next() + " ");
} // method run
}