List




import Person;

public class List {
  
   private Person data;
   private List vidare;
   private boolean empty;
   
   // constructors
   
   public List(Person in, List vid) {
      vidare=vid;
      empty=false;
      data = in;
   }
   
   public List() {
      empty=true;
   }
   
   public List concat(Person in) {
      List n = new List(in,this);
      return n;
   }
   
   public Person first() {
      return data;
   }
      
   public List rest() {
      return vidare;
   }
   
   public boolean isEmpty() {
      return empty;
   }
      

// Nedanstående funktion anväder du om du vill

   public void print() {
      if (isEmpty())
         return;
      first().print();
      rest().print();
   }

   public List addLast(Person el) {    //lägger till en person sist i kön
      if (isEmpty()) {
         List l=new List();
         List x=new List(el,l);
         return x;
      }
      return new List(first(),rest().addLast(el));
   }


}




Tillbaks till huvudsidan

email: Alireza.Niai_nouri.2077@student.uu.se