Skip to content

Instantly share code, notes, and snippets.

@adispen
Created April 27, 2014 21:54
Show Gist options
  • Save adispen/11356591 to your computer and use it in GitHub Desktop.
Save adispen/11356591 to your computer and use it in GitHub Desktop.
public static void shortestPath(Vertex[] friendGraph, String name1, String name2){
name1 = name1.toLowerCase();
name2 = name2.toLowerCase();
int n1Index = 0;
Stack<Vertex> friendStack = new Stack<Vertex>();
for(int j = 0; friendGraph[j].neighborList.next != null; j++){
System.out.println(friendGraph[j].name);
if(friendGraph[j].name.toLowerCase().equals(name1)){
n1Index = j;
}
if(friendGraph[j+1] == null){
continue;
}
}
friendStack = bfs(name2, n1Index, friendGraph);
while(!friendStack.empty()){
System.out.print(friendStack.pop().name + "--");
}
System.out.print(name2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment