所以,如果我想编写 Removelast() 方法,这行得通吗?这是给linkedListDS的我可以有一个没有其他的if吗?
public E removeLast() {
E result;
if(this.isEmpty())
{
System.out.println("No data present");
return null; //over here
}
result = tail.data;
if(this.size() == 1)
{
head= null;
tail= null;
}
else
{
Node<E> current;
current = head;
while(current.next != tail)
current= current.next;
tail = current;
tail.next=null;
}
return result;
}