列表的创建与个数读取

0 阅读1分钟

1.列表的创建

       public int first;
       public Intlist rest;
       
  public Intlist(int a,Intlist b)
       first=a;
       rest=b;
       }
       
       
      
正向创建
     Intlist a=new Intlist(5,null);
     a.rest=new Intlist(10,null);
     a.rest.rest=new Intlist(15,null);  
     
     
反向创建
     Intlist a=new Intlist(15,null);
             a=new Intlist(10,a);
             a=new Intlist(5,a);
          
    
    2.数列表的个数
    ```
public static int size(IntList p)
{
    int s=0;
    while(p!=null)
    {
        s=s+1;
        p=p.rest;
    }
    return s;
}
  ```