我想知道这段代码是否正确地模仿了使用链表的向量的“at”函数。这个概念是为了教我们链表,我不确定我是否将 pos++ 放在正确的位置。有人可以帮助我并告诉我每行在做什么,以便我知道它是如何退出 while 循环的吗?到现在为止,很混乱。谢谢你!
这是整个项目的pastebin:http: //pastebin.com/wyNQx3GP
多谢你们
// This returns the countyElectionResults result at a particular point
// in the list.
// This is analogous to the at method in the vector class.
countyElectionResults countyElectionList::at(int place){
if(head == NULL){
countyElectionResults * name = NULL;
return * name;
}
else{
countyElectionResults * current = head;
int pos = 0;
while(pos != place && current->getNextResult() != NULL){
current = current->getNextResult();
}
pos++;
return * current;
}
cout << "Not Found" << endl;
}