-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
849afe2
commit 4312506
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
int main() | ||
{ | ||
list<int> ls(5); | ||
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; | ||
// 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) // for each loop | ||
{ | ||
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 :*/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cout << endl; |