啊,知道了...刚开始用JS...感谢提醒

解决方案 »

  1.   

    js数组可以不指定大小用function构造类来实现链表:   
        
      <html>   
      <head>   
      <script   type="text/javascript">   
      function   myclass(value)   
      {   
      this.data=value;   
      this.next=null;   
        
      }   
      var   first=null;   
      var   last=null;   
      function   run()   
      {   
      a=new   myclass(document.getElementById("txt").value);   
      if   (first==null)   
      {   
      first=a;   
      last=a;   
      }   
      else   
      {   
      last.next=a;   
      last=a;   
      }   
      document.getElementById("txt").value="";   
      alert(a.data);   
      }   
      function   show()   
      {   
      for(temp=first;temp!=null;temp=temp.next)   
      {   
      alert(temp.data);   
      }   
      }   
      </script>   
      </head>   
      <body>   
      <input   type=text   width=10   id="txt">   
      <input   type=button   value="add"   onclick="run()">   
      <input   type=button   value="show"   onclick="show()">   
      </body>   
      </html>   
      该代码实现点击“add”将text   中的内容加入到链表中。点击“show”将整个链表的内容输出。你可以参考一下,树结构也可以由相似方法实现。