STL deque 코드

3881 단어
#include 
#include 

using namespace std;

int main(int argc, char* argv[])
{
    deque deq;
    for (int i = 0; i<6; i++)
    {
        deq.push_back(i);
    }

    cout << deq.size() << endl; //   :6
    cout << deq.max_size() << endl; //   :1073741823
    deq.resize(0); //       
    cout << deq.size() << endl; //   :0
    if (deq.empty())
        cout << "    " << endl; //   :    

    return 0;
}
#include 
#include 

using namespace std;

int main(int argc, char* argv[])
{
    deque deq;
    for (int i = 0; i < 8; i++)
        deq.push_back(i);

    //       
    deq.pop_front();
    //       
    deq.pop_back();
    //           
    deque::iterator it = deq.begin();
    deq.erase(it);
    //   [first,last]     
    deq.erase(deq.begin(), deq.begin()+1);

    //     
    for (it = deq.begin(); it != deq.end(); it++)
        cout << *it << " ";
    cout << endl;

    //       
    deq.clear();

    //     
    for (it = deq.begin(); it != deq.end(); it++)
        cout << *it << " "; //   :3 4 5 6
    cout << endl;

    return 0;
}
#include 
#include 

using namespace std;

int main(int argc, char* argv[])
{
    deque deq;
    for (int i = 0; i < 6; i++)
        deq.push_back(i);

    //     
    cout << deq[0] << endl; //   :0
    // at    
    cout << deq.at(0) << endl; //   :0
    //        
    cout << deq.front() << endl; //   :0
    //         
    cout << deq.back() << endl; //   :5

    return 0;
}
#include 
#include 

using namespace std;

int main(int argc, char* argv[])
{
    //       
    deque deq;
    deq.assign(3, 1);
    deque deq2;
    deq2.assign(3, 2);

    //          
    deq.swap(deq2);

    //     
    cout << "deq: ";
    for (int i = 0; i < deq.size(); i++)
        cout << deq[i] << " "; //   :2 2 2
    cout << endl;

    //     
    cout << "deq2: ";
    for (int i = 0; i < deq2.size(); i++)
        cout << deq2[i] << " "; //   :1 1 1
    cout << endl;

    return 0;
}
#include 
#include 
#include
using namespace std;
int main()
{
    deque a;
    deque::iterator it;
    for(it=a.begin();it<=a.end();it++)
    {
        cout<
#include 
#include 

using namespace std;

int main(int argc, char* argv[])
{
    deque deq;
    deq.push_back(1);
    deq.push_back(2);
    deq.push_back(3);

    cout << *(deq.begin()) << endl; //   :1
    cout << *(--deq.end()) << endl; //   :3
    cout << *(deq.cbegin()) << endl; //   :1
    cout << *(--deq.cend()) << endl; //   :3
    cout << *(deq.rbegin()) << endl; //   :3
    cout << *(--deq.rend()) << endl; //   :1
    cout << endl;

    return 0;
}
#include 
sort(deq.begin(), deq.end()); //            

//          ,             ,         :
//            ,        
bool Comp(const int& a, const int& b) {
    return a > b;
}

sort(deq.begin(), deq.end(), Comp);
deque::iterator it;
for (it = deq.begin(); it != deq.end(); it++)
    cout << *it << endl;
//   
for (int i = 0; i < deq.size(); i++) {
    cout << deq.at(i) << endl;
}

좋은 웹페이지 즐겨찾기