简体   繁体   English

如何为OrderedList类编写布尔移除方法

[英]How do I write a boolean remove method for an OrderedList class

Im kind of stumped right now, I need to write the remove method for an OrderedList class and this is what I have so far 我现在很困惑,我需要为OrderedList类编写remove方法,这是我到目前为止的内容

boolean remove(E obj) {
    ListIterator<E> iter = theList.listIterator();

    while (iter.hasNext()){
        if (obj.compareTo(iter.next()) == 0) {

        }
    }

    return false;
}   

I understand how the algorithm works by making the next item equal the previous but I just am not sure how to implement it. 我通过使下一项等于上一项来了解算法的工作原理,但是我不确定如何实现它。

https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html 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.

If you want to use the iterator, iter.remove(); 如果要使用迭代器, iter.remove();使用iter.remove(); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM