이 내 반복자 위치 코드RGD : 벡터 반복자가 얻을 수있는 인덱스 위치
struct node {
int nodeid;
vector<fingerTable> fTable;
vector<string> data;
};
vector<node> cNode;
vector<node>::iterator position = find(cNode.begin(),cNode.end(), id);
내가 약 100 개체를 가지고, 나는 가정 "80"예를 들어 nodeid가의 인덱스/요소/위치를 찾기 위해 노력하고 내 객체는 모두 nodeid에 의해 오름차순으로 정렬됩니다.
내 관심은, 내가 그것 .. 그것을 수정하거나 얻기에 어떤 제안이가 더 빨리 듣고 내가 이전에
for(int i=0;i<cNode.size();i++)
{
//if logic-- match nodeid with the nodeid input.. then assign the i to an integer..
}
을 사용했지만 지금은 내가 사용하려고하고 반복자하고 속도와 메모리 사용량입니다 그 값 "nodeid가"
에 의해 내 벡터 인덱스를 찾을 수있는 방법 내가지도가 내 경우에 대한 좋은 표준 컨테이너하지만 아이오와 비트 내가 벡터와 붙어있어 있도록 변경을 할 시간이 부족 알고 ..
vector<node>::iterator position = find(cNode.begin(),cNode.end(), id);
위의 반복자 행을 컴파일하려고하면 오류 출력이 발생합니다.
In member function ‘void chord::removePeer(int)’:
testfile.cpp:532:69: error: no matching function for call to ‘chord::find(std::vector<chord::node>::iterator, std::vector<chord::node>::iterator, int&)’
testfile.cpp:532:69: note: candidate is:
testfile.cpp:177:5: note: int chord::find(int, int, bool)
testfile.cpp:177:5: note: no known conversion for argument 1 from ‘std::vector<chord::node>::iterator {aka __gnu_cxx::__normal_iterator<chord::node*, std::vector<chord::node> >}’ to ‘int’
@billz 나는 을 포함하고, id는 정수이고, 그 고유하고 뚜렷하며 전체 벡터에서 한번만 나타납니다. 오름차순으로 정렬 됨 – user2017011
이 질문은 [어떻게 C++의 데이터로 벡터의 인덱스를 구할 수 있습니까?] (http://stackoverflow.com/q/14914985/78845) 11 시간 전부터 [I 응답 "std :: find()'는 선형 시간 (O (n))에서 실행되며, for 루프와 동일합니다."] (http://stackoverflow.com/a/14917460/78845). 비선형 시간에 실행하려면'std :: lower_bound()'를 사용하십시오. – Johnsyweb