GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — java_visualize/example-code/Forest.java at master · patrick-slagle/java_visualize Expand file tree/ Copy pathForest.javaMore file actions 34 lines (32 loc) · 1 KB / Copy pathForest.javaFile metadata and controls34 lines (32 loc) · 1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 // Princeton COS 126 Written Exam 2, Fall 2010, Question 3 // note: this is a proof-of-concept, but to do this on // paper you would instead skip as many internal steps of // root, merge, and merged as possible public class Node { private Node next; private int index; private Node root() { if (next == null) return this; return next.root(); } public static void merge(Node a, Node b) { a.root().next = b.root(); } public static boolean merged(Node a, Node b) { return a.root() == b.root(); } public static void main(String[] args) { Node[] f = new Node[8]; for (int i=0; i<8; i++) {f[i] = new Node(); f[i].index=i;} merge(f[0], f[3]); merge(f[1], f[2]); merge(f[1], f[4]); merge(f[5], f[6]); merge(f[3], f[4]); merge(f[7], f[5]); System.out.println(merged(f[0], f[3])); System.out.println(merged(f[0], f[7])); System.out.println(merged(f[1], f[3])); System.out.println(merged(f[4], f[5])); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |