Guest User

Untitled

a guest
Jun 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class NodeExample
  4. {
  5. public static void main(String[] args)
  6. {
  7. GraphNode a = new GraphNode(0,0,null);
  8. GraphNode b = new GraphNode(1,1,a);
  9. GraphNode c = new GraphNode(2,2,b);
  10. GraphNode d = new GraphNode(3,3,c);
  11.  
  12. ArrayList<GraphNode> nodeList = new ArrayList<GraphNode>();
  13. nodeList.add(a);
  14. nodeList.add(b);
  15. nodeList.add(c);
  16. nodeList.add(d);
  17.  
  18. //This is a java for-each loop.
  19. //It just steps through the elements in the ArrayList
  20.  
  21. Print("First time through");
  22. for(GraphNode n:nodeList)
  23. {
  24. if(n.parent != null)
  25. {
  26. Print(n);
  27. }
  28. }
  29.  
  30. Print("Changing parents");
  31. for(GraphNode n:nodeList)
  32. {
  33. n.SetParent(new GraphNode(10, 10, null));
  34. }
  35.  
  36. Print("Second time through");
  37. for(GraphNode n:nodeList)
  38. {
  39. if(n.parent != null)
  40. {
  41. Print(n.parent);
  42. }
  43. }
  44. }
  45.  
  46.  
  47. //This is just a silly class that I like to use cause I'm lazy
  48. //and I dont want to type System.out.println everytime I want to
  49. //print something
  50. public static void Print(Object o)
  51. {
  52. System.out.println(o);
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment