1. list使用:
数据结构的双链表一般来说对应stl中的list,并且list几乎提供了双链表操作的所有方法
常见的list操作有(至少是我用到的):
remove,
push_back,
</pre><pre name="code" class="cpp">#include<iostream>
#include <list>
using namespace std;
struct node
{
int key;
int val;
};
void main()
{
node * nn;
list<node*> ll;
for(int i=0; i<5; i++)
{
node * tmp=new node;
tmp->key=i;
ll.push_back(tmp);
if(i==3)
nn=tmp;
}
ll.remove(nn);
list<node*>::iterator it;
cout<<"all the data in the list is:"<<endl;
for(it=ll.begin(); it!=ll.end(); it++)
{
cout<<(*it)->key<<endl;
}
cout<<endl<<"after delete the node the original pointer's space is still exist"<<endl;
cout<<nn->key<<endl<<endl;
cout<<"ll's size is: "<<ll.size()<<endl;
}
原文地址:http://blog.csdn.net/jisuanji_wjfioj/article/details/46489409