unorderedlinkedlist.java
来自「这是有关java的应用 通过事例对java数据结构的链表的应用」· Java 代码 · 共 67 行
JAVA
67 行
package 音像店;
public class UnorderedLinkedList extends LinkedListClass {
public UnorderedLinkedList(UnorderedLinkedList otherList)
{
super(otherList);
}
public UnorderedLinkedList()
{
super();
}
public boolean search(DataElement searchItem)//搜索链表
{
LinkedListNode current;
boolean found;
current=first;
found=false;
while(current !=null && !found)
if(current.info.equals(searchItem)) found=true;
else
current=current.link;
return found;
}
public void deleteNode(DataElement deleteItem)
{
LinkedListNode current;
LinkedListNode trailCurrent;
boolean found;
if(first==null) System.err.println("Cannot delete from an empty list. ");
else
{
if(first.info.equals(deleteItem))
{
first=first.link;
if(first==null) last=null;
count--;
}
else
{
found=false;
trailCurrent=first;
current=first.link;
while(current!=null && !found)
{
if(current.info.equals(deleteItem)) found=true;
else
{
trailCurrent=current;
current=current.link;
}
}//end while
if(found)
{
count--;
trailCurrent.link=current.link;
if(last==current) last=trailCurrent;
}
else System.out.println("Item to be deleted is not in the list");
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?