Single Linked List Exercise

GUI參考類別

Run.java


public class Run {
   public static void main(String[] args) {
      Node node1 =new Node(99,null);
      Node temp = node1;

      for (int i = 97; i > 0; i -= 2) {
         temp = new Node(i, temp);
      }

      while(temp !=null){
         System.out.println(temp.key);
         temp = temp.next;
      }
   }
}

class Node {
   int key;
   Node next;
   public Node(int key, Node next) {
      this.key = key;
      this.next = next;
   }
}

參考實作