コード例 #1
0
ファイル: Solution.java プロジェクト: liondancer/leetcode
  public static void main(String[] args) {
    TreeLinkNode e = new TreeLinkNode(1);
    e.left = new TreeLinkNode(1);
    e.right = new TreeLinkNode(2);

    e.left.left = new TreeLinkNode(3);
    e.left.right = new TreeLinkNode(4);

    e.right.left = new TreeLinkNode(5);
    e.right.right = new TreeLinkNode(6);

    Solution s = new Solution();
    s.connect(e);
    s.printList(e.left);
    s.printList(e.left.left);
  }
コード例 #2
0
ファイル: Solution.java プロジェクト: nguyenxuantuong/algo
  public static void main(String[] args) {
    Solution solution = new Solution();

    Scanner scanner = new Scanner(System.in);

    ListNode head1 = solution.buildList(scanner.nextLine());
    ListNode head2 = solution.buildList(scanner.nextLine());

    ListNode cur = head1;
    while (cur != null && head2 != null) {
      ListNode next1 = cur.next;
      ListNode next2 = head2.next;

      cur.next = head2;
      head2.next = next1;

      head2 = next2;
      cur = next1;
    }

    solution.printList(head1);
    solution.printList(head2);

    scanner.close();
  }