The Duque Use :
//STL CONTAINER Deque
#include <bits/stdc++.h>
#define p_d_i(d) for(deque<int>::iterator it= d.begin();it!=d.end();it++)cout<<*it<<" ";cout<<endl;
using namespace std;
int main()
{
//same as vector
deque<int>d1;
deque<int>d2(7,89);
deque<int>d3(d2.begin()+2,d2.end()-1);
deque<int>d4(d2);
if(d1.empty())
cout<<"d1 is empty!\n";
cout<<d2[3]<<endl;
deque<int>d5(9); //size:9 all 0s
cout<<"Size of d5 is "<<d5.size()<<endl;
p_d_i(d5);
d4.push_back(13);
d4.push_back(52);
d4.push_front(976);
d4.push_front(56);
p_d_i(d4);
d4.pop_back();
p_d_i(d4);
d4.pop_front();
p_d_i(d4);
return 0;
}
--------------------------------------------------------------------------------------------
//STL CONTAINER Deque
#include <bits/stdc++.h>
#define p_d_i(d) for(deque<int>::iterator it= d.begin();it!=d.end();it++)cout<<*it<<" ";cout<<endl;
using namespace std;
int main()
{
//same as vector
deque<int>d1;
deque<int>d2(7,89);
deque<int>d3(d2.begin()+2,d2.end()-1);
deque<int>d4(d2);
if(d1.empty())
cout<<"d1 is empty!\n";
cout<<d2[3]<<endl;
deque<int>d5(9); //size:9 all 0s
cout<<"Size of d5 is "<<d5.size()<<endl;
p_d_i(d5);
d4.push_back(13);
d4.push_back(52);
d4.push_front(976);
d4.push_front(56);
p_d_i(d4);
d4.pop_back();
p_d_i(d4);
d4.pop_front();
p_d_i(d4);
d4.insert(d4.begin()+4,-12345);
d4.erase(d4.end()-1);
p_d_i(d4);
d4.erase(d4.end()-5);//Clear when erasing elements
//erase(begin) deletes the first element . But end -1 deletes the last element
p_d_i(d4);
d4.push_front(0);
p_d_i(d4);
d4.erase(d4.begin()); //deletes the first element
d4.push_back(67);
p_d_i(d4);
d4.erase(d4.end()-1); //deletes the last element
p_d_i(d4);
d4.clear();
if(d4.empty())
cout<<"d4 is empty too!\n";
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন