Guest User

Untitled

a guest
Nov 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5.  
  6. public class Ailink {
  7. private static final Graph graph = new Graph();
  8.  
  9. public static void main(String[] args) {
  10. new Ailink().run();
  11. }
  12.  
  13. public void run() {
  14. Scanner nm = new Scanner(System.in);
  15. System.out.println("spacebar x2 shows entire tree\n'remove'+(nodename) removes that node\n(nodename)+entr x2 shows all child nodes of that parent node\n(newparentnode)+entr+(newchildnode)+entr adds a new child node to a parent node");
  16.  
  17. for (int i = 0; i < 1000; i++) {
  18. System.out.println("Enter target:");
  19. String link1 = nm.nextLine();
  20.  
  21. if (link1.equals("exit")) {
  22. return;
  23. }
  24. Node targetNode = graph.findNode(link1);
  25.  
  26. if (targetNode != null) {
  27. System.out.println("Target's children: " + targetNode.printChildren() + "\n");
  28. } else if (link1.contains("remove")) {
  29. graph.deleteNode(link1.substring(7));
  30. }
  31.  
  32. if (!link1.contains("remove")) {
  33. System.out.println("Enter new value:");
  34. String link2 = nm.nextLine();
  35. if (!link2.isEmpty()) {
  36. graph.addNode(link1, link2);
  37. }
  38. else if (link2.isEmpty() && link1.isEmpty()) {
  39. System.out.println("");
  40. graph.print();
  41. System.out.println("");
  42. }
  43. }
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment