| 13 | } |
| 14 | |
| 15 | int main() |
| 16 | { |
| 17 | deque<int> dq; |
| 18 | dq.push_back(4); |
| 19 | dq.push_back(2); |
| 20 | dq.push_back(1); |
| 21 | dq.push_back(5); |
| 22 | dq.push_back(3); |
| 23 | |
| 24 | cout<<"Deque contains:"<<dq.size()<<" elements"<<endl; |
| 25 | |
| 26 | if (dq.empty()) |
| 27 | { |
| 28 | cout<<"Empty"<<endl; |
| 29 | } |
| 30 | else |
| 31 | { |
| 32 | cout<<"Empty"<<endl; |
| 33 | } |
| 34 | |
| 35 | //calling the function to print before sorting |
| 36 | print(dq); |
| 37 | //sorting the deque |
| 38 | sort(dq.begin(),dq.end()); |
| 39 | //calling the function to print after sorting |
| 40 | print(dq); |
| 41 | |
| 42 | //finding position of element with value 3 |
| 43 | auto it1=find(dq.begin(),dq.end(),3); |
| 44 | //Inserting element on a particular position of deque |
| 45 | //element gets inserted on previous position of it1 |
| 46 | dq.insert(it1,0); |
| 47 | print(dq); |
| 48 | |
| 49 | //removing the 1st element of deque |
| 50 | dq.erase(dq.begin()); |
| 51 | print(dq); |
| 52 | |
| 53 | dq.clear(); |
| 54 | cout<<"Deque contains:"<<dq.size()<<" elements"<<endl; |
| 55 | if(dq.empty()) |
| 56 | { |
| 57 | cout<<"Empty"<<endl; |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | cout<<"Not Empty"<<endl; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |