(BiNode root)
| 12 | } |
| 13 | |
| 14 | public static NodePair convert(BiNode root) { |
| 15 | if (root == null) { |
| 16 | return null; |
| 17 | } |
| 18 | |
| 19 | NodePair part1 = convert(root.node1); |
| 20 | NodePair part2 = convert(root.node2); |
| 21 | |
| 22 | if (part1 != null) { |
| 23 | concat(part1.tail, root); |
| 24 | } |
| 25 | |
| 26 | if (part2 != null) { |
| 27 | concat(root, part2.head); |
| 28 | } |
| 29 | |
| 30 | return new NodePair(part1 == null ? root : part1.head, part2 == null ? root : part2.tail); |
| 31 | } |
| 32 | |
| 33 | public static void concat(BiNode x, BiNode y) { |
| 34 | x.node2 = y; |