Skip to content

Instantly share code, notes, and snippets.

@hyuki
Last active May 7, 2021 05:58
Show Gist options
  • Select an option

  • Save hyuki/81b2ed0323de5953a61aaf7d1a25e154 to your computer and use it in GitHub Desktop.

Select an option

Save hyuki/81b2ed0323de5953a61aaf7d1a25e154 to your computer and use it in GitHub Desktop.
girlnote322.java
// https://twitter.com/hyuki/status/1390535639469158403/
class Node {
int value;
Node next;
public Node(int value, Node next) {
this.value = value;
this.next = next;
}
public static Node asNode(int... values) {
Node p = null;
for (int i = values.length - 1; i >= 0; i--) {
p = new Node(values[i], p);
}
return p;
}
public static void println(Node p) {
while (p != null) {
System.out.print(p.value);
p = p.next;
if (p != null) {
System.out.print(" → ");
}
}
System.out.println();
}
public static void main(String[] args) {
Node L = asNode(31, 41, 59, 26, 53);
Node p = L.next.next;
println(L);
//
L.next.next = p.next;
p.next = L;
L = p;
//
println(L);
}
}
@hyuki
Copy link
Copy Markdown
Author

hyuki commented May 7, 2021

$ java girlnote322.java
31 → 41 → 59 → 26 → 53
59 → 31 → 41 → 26 → 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment