-1
我有一个链接列表,其中包含项目。该项目有一个searchkey,我需要访问,所以我可以将其与我传递给tableDelete方法的字符串进行比较。如何访问链接列表项中的对象
基本上,我们通过一个城市的名称就是searchkey
喜欢说搜索链接列表,塞特是搜索键,我不知道如何head.getItem()
后访问它能够比较,所以我可以删除它,或者我想要。
c = new City("Narragansett", "USA", 12000);
chart.tableInsert(c);
因此以上城市是链表
public boolean tableDelete(KT searchKey) {
if(head.getItem().equals(searchKey)){
head = head.getNext();
return true;
}
Node current = head.getNext();
Node prev = head;
while(current!= null){
if(current.getItem().equals(searchKey)){
prev.setNext(current.getNext());
return true;
}
prev = current;
current = current.getNext();
}
return false;
}
什么问题? – Taylor
你能否详细说明这个问题。它不是很清楚。 –