Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class NodeExample
- {
- public static void main(String[] args)
- {
- GraphNode a = new GraphNode(0,0,null);
- GraphNode b = new GraphNode(1,1,a);
- GraphNode c = new GraphNode(2,2,b);
- GraphNode d = new GraphNode(3,3,c);
- ArrayList<GraphNode> nodeList = new ArrayList<GraphNode>();
- nodeList.add(a);
- nodeList.add(b);
- nodeList.add(c);
- nodeList.add(d);
- //This is a java for-each loop.
- //It just steps through the elements in the ArrayList
- Print("First time through");
- for(GraphNode n:nodeList)
- {
- if(n.parent != null)
- {
- Print(n);
- }
- }
- Print("Changing parents");
- for(GraphNode n:nodeList)
- {
- n.SetParent(new GraphNode(10, 10, null));
- }
- Print("Second time through");
- for(GraphNode n:nodeList)
- {
- if(n.parent != null)
- {
- Print(n.parent);
- }
- }
- }
- //This is just a silly class that I like to use cause I'm lazy
- //and I dont want to type System.out.println everytime I want to
- //print something
- public static void Print(Object o)
- {
- System.out.println(o);
- }
- }
Add Comment
Please, Sign In to add comment