list链表的格式(需要定义头文件)
list<int> data1(4, 100);list<int> data2(4, 500);
list链表的合并接口
举例使用合并接口并且验证
data2.merge(data1);list<int>::iterator ccc;for (ccc = data2.begin(); ccc != data2.end(); ccc++){cout << *ccc << endl;}cout << " ---------------------------- " << endl;
list链表的排序接口
data2.sort(mycomparison);
举例使用排序接口并且验证
// 插入接口data2.push_back(99);data2.push_back(88);data2.push_back(77);data2.push_back(66);data2.push_back(55);data2.push_back(44);// 排序接口data2.sort(mycomparison);for (ccc = data2.begin(); ccc != data2.end(); ccc++){cout << *ccc << endl;}cout << " ---------------------------- " << endl;
list链表的删除接口
data2.remove(500);
举例使用删除接口并且验证
500这个元素被从链表中删除
data2.remove(500);for (ccc = data2.begin(); ccc != data2.end(); ccc++){cout << *ccc << endl;}cout << " delete ---------------------------- " << endl;
举例使用倒转接口并且验证
data2.reverse();
举例使用倒转接口并且验证
可以看到数据倒转了
data2.reverse();for (ccc = data2.begin(); ccc != data2.end(); ccc++){cout << *ccc << endl;}