-
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
ba4c302
commit c9206c7
Showing
4 changed files
with
69 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,53 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
deque<int> dq(5); | ||
deque<int> copy(2, 100); | ||
for (auto it = dq.begin(); it != dq.end(); it++) | ||
{ | ||
cout << "enter element: "; | ||
cin >> *it; // Dereference the iterator to access the element and read into it | ||
} | ||
dq.erase(dq.begin() + 1); | ||
dq.insert(dq.begin() + 1, copy.begin(), copy.end()); | ||
cout << "deque elements : "; | ||
for (auto it : dq) // for each loop | ||
{ | ||
cout << it << " "; | ||
} | ||
dq.pop_back(); | ||
cout << endl; | ||
cout << "Pop deque elements : "; | ||
for (auto it : dq) // for each loop | ||
{ | ||
cout << it << " "; | ||
} | ||
cout << endl; | ||
dq.swap(copy); | ||
|
||
cout << "Swap deque elements : "; | ||
for (auto it : dq) // for each loop | ||
{ | ||
cout << it << " "; | ||
} | ||
dq.clear(); | ||
cout << endl; | ||
cout << "Clear deque elements : "; | ||
for (auto it : dq) // for each loop | ||
{ | ||
cout << it << " "; | ||
} | ||
|
||
return 0; | ||
} | ||
/*enter element: 1 | ||
enter element: 2 | ||
enter element: 3 | ||
enter element: 4 | ||
enter element: 5 | ||
deque elements : 1 100 100 3 4 5 | ||
Pop deque elements : 1 100 100 3 4 | ||
Swap deque elements : 100 100 | ||
Clear deque 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,16 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
int main() | ||
{ | ||
deque<int> dq; | ||
dq.push_front(1); | ||
dq.push_front(2); | ||
dq.push_front(3); | ||
cout << dq[0] << " " << dq[1] << " " << dq[2]; | ||
cout << endl | ||
<< "after pop "; | ||
dq.pop_back(); | ||
cout << dq[0] << " " << dq[1] << " " << dq[2]; | ||
|
||
return 0; | ||
} |
Binary file not shown.