コード例 #1
0
 public String printForward() {
   String data = "(" + key + "," + value + ")";
   if (next != null) {
     return data + "->" + next.printForward();
   } else {
     return data;
   }
 }
コード例 #2
0
ファイル: FindNth.java プロジェクト: yw229/LinkedList
  public static void main(String[] args) {
    LinkedListNode node = method.randomLinkedList(10, 0, 10);
    System.out.println(node.printForward());
    int nth = 2;
    LinkedListNode n = nthNode(node, nth);
    try {
      FileWriter write = new FileWriter("findn.txt");
      PrintWriter out = new PrintWriter(write);
      if (n != null) out.println(nth + "th to last node is " + n.data);
      else out.println("null");

      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }