GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java_visualize/example-code/Forest.java at master · patrick-slagle/java_visualize

Expand file tree

/

Forest.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (32 loc) · 1 KB
/

Forest.java

Copy path

File metadata and controls

34 lines (32 loc) · 1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.