Article View: cn.bbs.comp.lang.java
Article #18667Re: �����javaʵ������Ĺ���?
From: �����ǹӢ�ۺ�
Date: Mon, 02 Feb 2004 08:27
Date: Mon, 02 Feb 2004 08:27
143 lines
4265 bytes
4265 bytes
let me try
//file 1: element class
public SingleListElem
{
//fields
protected Object data; //data: contain element's value
protected SingleListElem nextElem; //next element
//constructor
public SingleListElem(Object data, SingleListElem next)
{
this.data = data;
this.nextElem = next;
}
public SingleListElem(Object data)
{
SingleListElem(data, null);
}
//non-static method
//set the nextElem value
public void setNext(SingleListElem next)
{
nextElem = next;
}
//return value(or data)
public Object value()
{
return data;
}
//set value
public void setValue(Object value)
{
data = value;
}
}
//file 2: list class
public class SingleList
{
//field
protected long count;
protected SingleListElem head;
//constructor
public SingleList()
{
head = null;
count = 0;
}
//return size
public long size()
{
return count;
}
public boolean isEmpty()
{
return size()==0;
}
//add element to head
public void addToHead(Object value)
{
head = new SingleListElem(value, head);
count++;
}
//remove element from head
public Object removeFromHead()
{
SingleListElem tmp = head;
head = head.next();
count--;
return tmp;
}
//add element to tail
public void addToTail(Object value)
{
SingleListElem tmp = new SingleListElem(value,null);
if(head!=null) {
SingleListElem pointor = head;
while(pointor.next()!=null) {
pointor = pointor.next();
}
pointor.setNext(tmp);
} else head = tmp;
count++;
}
//remove from tail
public Object removeFromTail()
{
SingleListElem pointor = head;
SingleListElem pre = null;
while(pointor.next()!=null) {
pre = pointor;
pointor = pointor.next();
}
if(pre == null) head = null;
else pre.setNext(null);
count--;
return pointor.value;
}
public clear()
{
head = null;
count = 0;
}
//and other method such as contains, remove, toString...
//I think it is easy for you ,hehe
}
�� �� Narcissus.bbs@bbs.sjtu.edu.cn (ֻ��������) �Ĵ������ᵽ: ��
: class a
: {
: a next;
: }
: right?
: �� �� webmate.bbs@freecity.cnzju.net (տ��) �Ĵ������ᵽ: ��
: : ������ Reference
: : ����
: : WeakReference
: >> .................<����ʡ��>............
--
ÿ���˶���������ס�
һ�����Լ����е��Լ���һ�����������е��Լ�������һ���ǣ�
������Լ���������ܿ���������Լ��أ�
����ǣ����Լ�ʧȥһ�е�ʱ��Ż����װɡ�
��ô��Ҳ�?֪��������һ���Ҹ��ˡ�
[m[1;32m�� ��Դ:��Ʈ��ˮ�Ƽ� freecity.cnzju.net��[FROM: vernunft][m
Technical Details
Message-ID:
<4AUd5I$AGI@freecity.cnzju.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!fr.ip.ndsoftware.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.usenetserver.com!news.bylinux.net!news.ccie.net.cn!FreecityShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,GB X-Google-Thread: f6cb0,c597b2b1e6390d59 X-Google-Attributes: gidf6cb0,public X-Google-ArrivalTime: 2004-02-02 00:25:10 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!fr.ip.ndsoftware.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.usenetserver.com!news.bylinux.net!news.ccie.net.cn!Freecity From: vernunft.bbs@freecity.cnzju.net (�����ǹӢ�ۺ�) Newsgroups: cn.bbs.comp.lang.java Subject: Re: �����javaʵ������Ĺ���? Date: 02 Feb 2004 08:27:15 GMT Organization: Ʈ��ˮ�Ƽ� Message-ID: <4AUd5I$AGI@freecity.cnzju.net> Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: 8bit X-Filename: Java/M.1075707906.A Lines: 143