Guest User

Untitled

a guest
Jan 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. public String[] findLink(String fW,String sW){
  2.         Node lastNode=new Node(fW);
  3.         Node goalNode=new Node(sW);
  4.  
  5.         while(true){
  6.             ArrayList<Node> traversedNodes=new ArrayList<Node>();       //  Instantiating a list of nodes it's been through, new for each iteration of the loop
  7.             traversedNodes.add(lastNode);                               //  Adding the last Node
  8.             lastNode.getConnections();                                  //  Getting the connections of the last Node
  9.             for(Connector connection:lastNode.getConnections()){        //  Testing the last Node'sconnections         
  10.                 if(lastNode==connection.getOne())       lastNode=connection.getOne();   //  For each connection will get the other end of connector
  11.                 else if(lastNode==connection.getTwo())  lastNode=connection.getTwo();
  12.                 if(lastNode.getWord()==goalNode.getWord()) break;              
  13.             }
  14.             if(lastNode!=goalNode){
  15.                 String[] links=new String[traversedNodes.size()];           //  Converting ArrayList into String[]
  16.                 for(int i=0;i==traversedNodes.size();i++){
  17.                     links[i]=traversedNodes.get(i).getWord();
  18.                 }
  19.                 return links;
  20.             }
  21.         }
  22.     }
Add Comment
Please, Sign In to add comment