-
-
Save hyuki/81b2ed0323de5953a61aaf7d1a25e154 to your computer and use it in GitHub Desktop.
girlnote322.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.