
public class oct19
{
 
 public cell front;  // good old front pointer

 static boolean member(int x, cell L)
  { return  (L!=null) && 
            (L.head == x || member(x,L.tail));
  }

 // non-destructive append
 static cell append(cell L, cell M)
  { if (L == null) return M;    
      else return new cell(L.head,append(L.tail,M));
  }
  
 // destructive append - note, not static!
 void destruct_append(cell M)
  { front = append(front,M); }
  

 static int length(cell L)
  { if (L == null) return 0;
      else return 1 + length(L.tail);
  }

 static cell reverse(cell L)
  { if (L == null) return null;
      else return append(reverse(L.tail),new cell(L.head,null));
  }

 // "tail-recursive" version:
 static private cell reverse_iter(cell L, cell ax)
  { if (L == null) return ax;
      else return reverse_iter(L.tail, new cell(L.head,ax));
  }
 static cell reverse2(cell L)  // only takes one arg
  { return reverse_iter(L,null); }

 // deletes all occurrences of x from L
 static cell deleteall(int x, cell L)
  { if (L == null) return null;
      else 
       if (L.head == x) return deleteall(x,L.tail);
	 else return new cell(L.head,deleteall(x,L.tail));
  }

 // destructive delete
 void delete_destroy(int x)
  { front = deleteall(x,front); }
 
 
 // remove duplicates
 static cell remdups(cell L)
  { if (L == null) return null;
      else return new cell(L.head,remdups(deleteall(L.head,L.tail)));
  }  //  ain't that pretty?

  
 public static void main(String[] args)
  {
    oct19 mylist = new oct19();
    cell A, B, C, D;    
    A = new cell(1,new cell(3,new cell(5,null)));
    B = new cell(2,new cell(4,new cell(6,null)));

  } // end main


} // end class oct19


class cell 
{ 
  int head;
  cell tail;
  public cell(int h, cell t)  { head = h; tail = t; }
}
