iam應該顯示一個txt文件中的客戶記錄,然後按照升序重新顯示它們。我有第一部分,但沒有弄清楚排序問題。方法public void添加(客戶newNode,詮釋虛擬)排序實施的鏈接列表
public void add(Customer newNode, int dummy)
{
if (head == null) // The first node
{
head = tail = this;
head.setData(newNode); size=1;
return;
} //************need to figure this out
CustomerList t = new CustomerList();
head.setNext(temp);
getHead().getNext();
head = temp;
//this is the part am trying to figure out
++size;
} // add
// Append the new node to the end of list
public void add(Customer newNode)
{
if (head == null) // The first node
{
head = tail = this;
head.setData(newNode);
size=1;
return;
}
CustomerList temp = new CustomerList(newNode);
tail.setNext(temp);
getHead().getNext();
tail = temp;
++size;
} // add
// retrieve a specific node by index
// The index starts with 0
public Customer get(int which)
{
if (which > size-1)
return null;
if (size < 0)
return null;
CustomerList temp = head;
for (int k=0; k < size; ++k)
{
if (which == k)
break;
temp = temp.getNext();
}
return temp.getData();
} // get
是否允許使用「標準java」類似於集合和算法的東西,還是您希望自己完成所有工作? – John3136 2012-03-26 04:57:04