-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlist.cpp
52 lines (50 loc) · 1.23 KB
/
list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
int main()
{
list<int> ls(9);
vector<int> copy(2, 100);
for (auto it = ls.begin(); it != ls.end(); it++)
{
cout << "enter element: ";
cin >> *it; // Dereference the iterator to access the element and read into it
}
ls.erase(next(ls.begin(), 1));
ls.insert(next(ls.begin(), 1), copy.begin(), copy.end());
cout << "list elements : ";
for (auto it : ls) // for each loop
{
cout << it << " ";
}
ls.pop_back();
cout << endl;
cout << "Pop list elements : ";
for (auto it : ls) // for each loop
{
cout << it << " ";
}
cout << endl;
//swap
// ls.swap(copy);swap does not work with diffrent container
// cout << "Swap lstor elements : ";
// for (auto it : ls) // for each loop
// {
// cout << it << " ";
// }
ls.clear();
cout << endl;
cout << "Clear list elements : ";
for (auto it : ls)
{
cout << it << " ";
}
return 0;
}
/*enter element: 1
enter element: 2
enter element: 3
enter element: 4
enter element: 5
list elements : 1 100 100 3 4 5
Pop list elements : 1 100 100 3 4
Clear list elements :*/