怎么取LIST的值

来源:百度知道 编辑:UC知道 时间:2024/06/19 15:11:28
像VECTOR我可以用下标方式取它的值拿来显示或者他用。
MAP我也可以用ITERATOR来这个迭代器来定义一个泛型的指针,
然后用这个指针-》FIRST。取值。
但是LIST是链表的连接方式,我怎么取显示取LIST里面的值呢?

和vector很像的,也可以用ITERATOR来这个迭代器来定义一个泛型的指针
list<int> the_list;
for( int i = 0; i < 10; i++ )
the_list.push_back( i );
while( !the_list.empty() ) {
cout << the_list.front() << endl;
the_list.pop_front();
}

链表:
first->[内容1|next]->[内容2|next]->......
只需要记住头指针,然后通过循环不断提取下一位置处的next指针直至找到自己需要的内容。