class LNode{
public int data;
public LNode next;
public LNode(int d){
data=d;
next=null;
}
public LNode(int d,LNode next){
data=d;
this.next=next;
}
}public class WashCards{
public static void main(String[] args){
LNode head=new LNode(1);
LNode w=head;
System.out.print(head.data+",");
for(int i=2;i<55;i++){
w=w.next;
w.data=i;
System.out.print(w.data+",");
}
}
}

解决方案 »

  1.   

    自己想出来了
    +
    w.next=new LNode(0);
    就OK了。
      

  2.   

    如果不改动你的LNodepublic class WashCards{
    public static void main(String[] args){
    LNode w = new LNode(54);
    for (int i = 54; --i > 0; w = new LNode(i, w));
    LNode head = w;
    while (w != null) {
    System.out.print(w.data + ",");
    w = w.next;
    }
    }
    }例外,洗牌不叫wash,叫shuffle
      

  3.   

    改一下,如果只要构造而不打印,这样最快,代码最少
    LNode head = null;
    for (int i = 54; i > 0; head = new LNode(i--, head));:P