标签:
链表添加元素,然后插入、删除、最后遍历
#include "stdafx.h" #include <string> #include <list> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { list<string> staff; staff.push_back("Cracker, Carl"); staff.push_back("Cacker, Harry"); staff.push_back("Lam, Larry"); staff.push_back("Sandam, Susan"); /* add a value in fourth place */ list<string>::iterator pos; pos = staff.begin(); pos++; pos++; pos++; staff.insert(pos, "Reindeer, Rudolf"); /* remove the value in second place */ pos = staff.begin(); pos++; staff.erase(pos); /* print all values */ for ( pos = staff.begin(); pos != staff.end(); pos++ ) cout << *pos << "\n"; system("pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/david-zhao/p/5085753.html