Пример #1
0
  /*
  Method: toString
  Purpose: sends the database to a string
  Parameters:
      TreeNode currentNode - the current node in the binary tree
  Returns:
  */
  private String toString(TreeNode currentNode) {
    String returnString = "";
    if (currentNode == null) {
      return returnString;
    }

    returnString += toString(currentNode.getLeftBranch());
    returnString += currentNode.toString() + "\r\n";
    returnString += toString(currentNode.getRightBranch());

    return returnString;
  }
Пример #2
0
 /*
 Method: toFile
 Purpose: sends the database to a File
 Parameters:
     FileWriter fileWriter - the filewriter to pprint to file
     TreeNode current - current node bing printed
 Returns:
 */
 public void writeToFile(FileWriter fileWriter, TreeNode current) {
   try {
     if (current == null) {
       return;
     }
     fileWriter.write(current.toFile() + "\r\n");
     writeToFile(fileWriter, current.getLeftBranch());
     writeToFile(fileWriter, current.getRightBranch());
   } catch (IOException exception) {
     System.out.println("An error occurred in the file writing");
   }
 }
Пример #3
0
  private String searchForSynonym(String searchedFor, TreeNode currentNode) {
    String returnString = "";

    if (currentNode == null) {
      return returnString;
    }

    returnString += searchForSynonym(searchedFor, currentNode.getLeftBranch());

    if (currentNode.containsSynonym(searchedFor)) {
      returnString += "\r\n" + currentNode.toString() + "\r\n";
    }

    returnString += searchForSynonym(searchedFor, currentNode.getRightBranch());

    return returnString;
  }