Skip to content

Commit

Permalink
Dequeue cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishak798 authored Feb 10, 2024
1 parent ba4c302 commit c9206c7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Dequeue/dq.cpp
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 added Dequeue/dq.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions Dequeue/dqprac.cpp
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 added Dequeue/dqprac.exe
Binary file not shown.

0 comments on commit c9206c7

Please sign in to comment.