for(auto it = M.begin(); it!=M.end();it++)
{
cout<<it->first<<" "<<it->second<<"\n";
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作得很好但是,
for(auto it : M)
{
if(it->second == 1) return it->first;
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误。
为什么我必须使用it.secondandit.first而不是it->secondand it->first?
这是打印链表元素的解决方案。
为什么不是Node *current = new Node;然后current = head;呢?
void printLinkedList(Node* head)
{
Node *current = head;
while(current!=NULL){
cout << current -> data << endl;
current = current -> next;
}
}
Run Code Online (Sandbox Code Playgroud)