LinkedList接口的实现

时间:2012-09-20 09:37:53

标签: java linked-list

我想使用链接列表界面添加多个元素.....我的代码是:

import java.util.*;

public class LList 
{
      public static void main(String[] args) 
      {
          Node node;

          Random rand = new Random();
          int Threshold = 10;
          long P,D,Du;

          LinkedList<Node> ll = new LinkedList<Node>();


          for(int i =1;i<=Threshold;i++)
          {  
              Calendar c = new GregorianCalendar();
              long m = c.get(GregorianCalendar.SECOND);
              Du = rand.nextInt(4);
              P =   rand.nextInt(10)+1;
              D = Period + m;
                  node = new Node("T"+i, m, Du, P, D);
                          ll.add(node)
              System.out.println("The content of linklist is: " + ll);
              System.out.println("The size of linklist is: " + ll.size());
         } 



      }
    }

//节点类

import java.util.LinkedList;


public class Node extends LinkedList
{

     long du;
     long p,Arr,d;
     String task;
     Node next;  

     public Node(String Task,long arr,long dur, long per,long d1)  
     { 
         task=Task;
         Arr = arr;
         du = dur;
         p = per;
         d = dl;
     }  

     public void displayNode()  
     {  
            System.out.print(task+","+Arr+","+du+","+p+","+d+"\n");

     }

}  

输出:

链接列表的内容为:[[],[],[],[],[],[],[],[],[],[]] 链表的大小为:10

它没有显示值......我实现这个接口错了吗?

1 个答案:

答案 0 :(得分:1)

Node是列表的元素。它不需要扩展LinkedList。此外,在课程toString中覆盖Node,而不是使用diaplayNode