现在我们要用list中的insert函数
-
先搜索list
-
找到list::insert(一般在左侧)
-
复制这三个函数
//single element (1)
iterator insert (iterator position, const value_type& val);
//fill (2)
void insert (iterator position, size_type n, const value_type& val);
//range (3)
///template <class InputIterator>
void insert (iterator position, InputIterator first, InputIterator last);
对其进行分别实现调用
#include<iostream>
#include<list>
using namespace std;
//(1)iterator insert(iterator position, const value_type& val);
//(2)void insert(iterator position, size_type n, const value_type& val);
//(3)void insert(iterator position, InputIterator first, InputIterator last);
void main()
{
list<int>lt1;
lt1.insert(lt1.end(), 5);
for (const auto& e : lt1)
cout << e << "——>";
cout << "Over." << endl;
lt1.insert(lt1.end(), 3, 7);
for (const auto& e : lt1)
cout << e << "——>";
cout << "Over." << endl;
int ar[] = { 3, 4, 7, 6 };
int n = sizeof(ar) / sizeof(ar[0]);
list<int> lt4(ar, ar + n);
lt1.insert(lt1.end(), lt4.begin(), lt4.end());
for (const auto& e : lt1)
cout << e << "——>";
cout << "Over." << endl;
}
#include<iostream>
#include<list>
using namespace std;
//(1)iterator insert(iterator position, const value_type& val);
//(2)void insert(iterator position, size_type n, const value_type& val);
//(3)void insert(iterator position, InputIterator first, InputIterator last);
void main()
{
list<int>lt1;
lt1.insert(lt1.end(), 5);
for (const auto& e : lt1)
cout << e << "——>";
cout << "Over." << endl;
lt1.insert(lt1.end(), 3, 7);
for (const auto& e : lt1)
cout << e << "——>";
cout << "Over." << endl;
int ar[] = { 3, 4, 7, 6 };
int n = sizeof(ar) / sizeof(ar[0]);
list<int> lt4(ar, ar + n);
list<int>::iterator start = lt4.begin();
list<int>::iterator end = lt4.begin();
end++;
end++;
lt1.insert(lt1.end(), start,end);
for (const auto& e : lt1)
cout << e << "——>";
cout << "Over." << endl;
}