java问题请教

vincentdeng1986 2010-03-15 08:38:44
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对象的属性到底能存什么。能存一个链表?各位大虾帮助,谢谢了~~
...全文
145 8 打赏 收藏 转发到动态 举报
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
小余 2010-03-17
  • 打赏
  • 举报
回复
没懂的起~~~~~~~~~~~~~~~
zings 2010-03-15
  • 打赏
  • 举报
回复
Java 链表?.........
科學信仰 2010-03-15
  • 打赏
  • 举报
回复
至于head是Object的,或是为了增加弹性,或是为了增添迷惑,或...未知
Object可以是PTList
科學信仰 2010-03-15
  • 打赏
  • 举报
回复
PTList,list of points? 当其是一个简单链表来实现吧

观此构成 1->2->3->null
PTlist成员需要有value,有next

private int value;
private PTList next;

在cons方法中构造链表,当使用时就能从头遍历到尾
ladybirds2008 2010-03-15
  • 打赏
  • 举报
回复
这是一个基础问题。。。还是好好想想吧。。。
sing4j 2010-03-15
  • 打赏
  • 举报
回复
传递一个数组。。。。。
vincentdeng1986 2010-03-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mawentao728 的回复:]

要完成这个类,没说功能吗?
[/Quote]
在其他类中调用这个类的方法public static PTList cons(Object hd, PTList tl),但实际上传入进来的是一系列数字,toString()方法就是输出1->2->3->4->5->null的一个东西
Trinx 2010-03-15
  • 打赏
  • 举报
回复
要完成这个类,没说功能吗?
相关推荐

62,568

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告