[英]How do I write a boolean remove method for an OrderedList class
我現在很困惑,我需要為OrderedList類編寫remove方法,這是我到目前為止的內容
boolean remove(E obj) {
ListIterator<E> iter = theList.listIterator();
while (iter.hasNext()){
if (obj.compareTo(iter.next()) == 0) {
}
}
return false;
}
我通過使下一項等於上一項來了解算法的工作原理,但是我不確定如何實現它。
https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html
boolean remove(Object o)
Removes the first occurrence of the specified element from this list, if it is present.
如果要使用迭代器, iter.remove();
使用iter.remove();
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.