public class PTList
{
// Instance members,
// hd is the object at the head of the list
// tl is the tail of the list
// null indicates the end of list and an empty list.
private Object hd;
private PTList tl; // The constructor is private - PTList objects can only be created by cons.
private PTList() {} /**
 * Return the tail of the list.
 * @return The tail of this list.
 */
public PTList tail()
{
return null ; // replace this code
} /**
 * Return the head of the list.
 * @return The Object at the head of this list.
 */
public Object head()
{
return null ; // replace this code
}
/**
 * Create a new PTList object with hd as the value at the head of the list
 * and tl as the tail of the list.
 * @param hd The value at the head of the PTList.
 * @param tl The tail of the new PTList.
 * @return A new PTList object.
 */
public static PTList cons(Object hd, PTList tl)
{
//return null ; // replace this code
PTList newptList=new PTList();
newptList.hd=hd;
newptList.t1=t1;
return newptList;
}
/**
 * Returns a list consisting of the elements of PTList a joined to PTList b.
 * For example
 * <br>if a is: 1->2->3->null and b is: 4->5->null
 * <br> then append(a,b) is 1->2->3->4->5->null
 * @param a The first part of the new PTList.
 * @param b The second part of the new PTList.
 * @return The new PTList.
 */
public static PTList append(PTList a, PTList b)
{
return null ; // replace this code
}
/**
 * Returns a string consisting of the form "" + {@link PTList#head head()} + "->" + {@link PTList#tail tail()}.
 * An empty list is represented by null.
 * @return The correctly formatted String.
 */
// Do not modify this method.
public String toString()
{
return "" + hd + "->" + tl;
}
}请问这样一个类到底是什么意思?我们的作业要求完成这个类。在其他地方调用该类的方法,传的参数是一系列数字,但是搞不明白这个Object对象的属性到底能存什么。能存一个链表?各位大虾帮助,谢谢了~~

解决方案 »

  1.   

    在其他类中调用这个类的方法public static PTList cons(Object hd, PTList tl),但实际上传入进来的是一系列数字,toString()方法就是输出1->2->3->4->5->null的一个东西
      

  2.   

    PTList,list of points? 当其是一个简单链表来实现吧观此构成 1->2->3->null
    PTlist成员需要有value,有nextprivate int value;
    private PTList next;在cons方法中构造链表,当使用时就能从头遍历到尾
      

  3.   

    至于head是Object的,或是为了增加弹性,或是为了增添迷惑,或...未知
    Object可以是PTList