小编TMG*_*ter的帖子

在java中寻求对迭代器的进一步理解

如果我使用for循环(循环标准,而不是增强的for语句),我无法看到迭代器在搜索集合时如何提高效率.如果我有一个如下声明:

(假设aList是通用对象的List,键入E,nextElement引用列表中的下一个元素)

for (int index = 0; index < aList.size(); index++){
E nextElement = aList.get(index);
// do something with nextElement...
}
Run Code Online (Sandbox Code Playgroud)

我有一个看起来像这样的get方法:

Node<E> nodeRef = head;
for (int i = 0; i < index; i++){
    nodeRef = nodeRef.next;
    // possible other code
}
Run Code Online (Sandbox Code Playgroud)

这基本上是在列表中搜索,一次一个元素.但是,如果我使用迭代器,它不会执行相同的操作吗?我知道迭代器应该是O(1)速度,但如果必须搜索整个列表,它不会是O(n)吗?

java algorithm performance iterator

5
推荐指数
2
解决办法
473
查看次数

Qt LNK2019基本Qt5应用程序出错

我正在尝试在线学习教程并使用QtCreator 2.6.1学习Qt5

但是,我尝试按照本教程编写基本应用程序,每当我尝试构建项目时,我都会收到链接错误:

#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello World");
    label->show();

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

点击"Build"后,我得到大约50个错误,类似于以下内容:

main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWidget::show(void)" (__imp_?show@QWidget@@QAEXXZ) referenced in function _main
Run Code Online (Sandbox Code Playgroud)

有没有办法通过链接库等来解决这个问题(假设它们没有正确链接)?如果没有,我还能做些什么来尝试解决这个问题?

c++ qt compiler-errors lnk2019 qt5

4
推荐指数
1
解决办法
1万
查看次数

无法从Node <E>转换为Node <E>?

我只是从我的一本书中做了一些练习,我很好奇为什么我在eclipse中得到以下错误:

Type mismatch: cannot convert from type DoublyLinkedList.Node<E> to DoublyLinkedList.Node<E>

码:

import java.util.Iterator;
    import java.util.ListIterator;
    import java.util.NoSuchElementException;


public class DoublyLinkedList<E extends Comparable<E>> implements Iterable<E>{

 private int size = 0;
 private Node<E> head;
 private Node<E> tail;

/** Returns a list iterator object for the list at 
 * the specified index
 */

 public DoublyLinkedList(){


}



private static class Node<E> {

    Node<E> next = null;
    Node<E> prev = null;
    E data;

    public Node(E dataItem){
        data = dataItem;
    }

    public Node(E dataItem, Node<E> previous, …
Run Code Online (Sandbox Code Playgroud)

java iterator linked-list

1
推荐指数
1
解决办法
3834
查看次数