📄 unorderedlinkedlist.java
字号:
public class UnorderedLinkedList extends LinkedListClass{
public UnorderedLinkedList()
{
super();
}
public UnorderedLinkedList(UnorderedLinkedList otherList)
{
super(otherList);
}
public boolean search(DataElement searchItem) {
// TODO Auto-generated method stub
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) {
// TODO Auto-generated method stub
LinkedListNode current;
LinkedListNode trailCurrent;
boolean found;
if(first==null)
System.out.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;
}
}
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -