当前位置: 首页>>代码示例>>C++>>正文


C++ PriorityQueue::length方法代码示例

本文整理汇总了C++中PriorityQueue::length方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::length方法的具体用法?C++ PriorityQueue::length怎么用?C++ PriorityQueue::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue::length方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testPriorityQueue

void testPriorityQueue(){
    PriorityQueue<int> mycontainer;

    cout << "\n\n Begin test function for the PriorityQueue<T> class\n";

    // Testing the enqueue function
    cout << "Testing size of new empty container: " << mycontainer.length() << endl;
    cout << "Testing enqueue(1), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.enqueue(1);
    cout << "Size is " << mycontainer.length() << endl;
    cout << "Testing enqueue(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.enqueue(2);
    cout << "Size is " << mycontainer.length() << endl;
    cout << "Testing enqueue(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.enqueue(2);
    cout << "Size is " << mycontainer.length() << endl;
    cout << "Testing enqueue(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.enqueue(2);
    cout << "Size is " << mycontainer.length() << endl;
    cout << "Testing enqueue(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    mycontainer.enqueue(2);
    cout << "Size is " << mycontainer.length() << endl;
    cout << "Testing enqueue(2), length(), and isEmpty() functions. mycontainer is empty? "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");
    cout << "Size is " << mycontainer.length() << endl << endl;

    int size = mycontainer.length();
    cout << "Testing pop_back(), front(), back(), length() and isEmpty() functions \n"
            << "in a for loop with iterations greater than container size.";
    for (int i = 0; i < size + 1; i++) {
        cout << "\nIteration: " << i + 1 << "\n";
        if (!mycontainer.isEmpty()) {
            cout << " mycontainer is empty? " << (mycontainer.isEmpty() ? " true\n" : "false\n");
            cout << "PriorityQueue size before pop is " << mycontainer.length() << endl;
            //cout<<"Front of container is " << mycontainer.front()<<endl;
            //cout<<"Back of container is " << mycontainer.back()<<endl;
            //cout << "Popping: " << mycontainer.front() << endl << endl;
            mycontainer.pop_back();
        } else {
            cout << "The PriorityQueue is empty.\n";
        }

        cout << "PriorityQueue size is now: " << mycontainer.length() << endl;
    }
    cout << "\nFinished for loop\n";

    cout << "\nTesting the reference for front() and back() functions.\n";
    cout << "Start with int test = 7. mycontainer.enqueue(test)\n";
    int test = 7;
    mycontainer.enqueue(test);
    cout << "Testing with test = 8. test=mycontainer.front(). mycontainer.front() = 13 \n";
    test = 8;
    test = mycontainer.front();
    mycontainer.front() = 13;
    cout << "Test is now " << test << " front of container is " << mycontainer.front()
            << " back of container is " << mycontainer.back() << endl;
    test = 11;
    mycontainer.enqueue(test);
    cout << "Back of container is: " << mycontainer.back() << endl;
    cout << "Test is now " << test << " front of container is " << mycontainer.front()
            << " back of container is " << mycontainer.back() << endl;
    mycontainer.back() = test;
    cout << "Test is now " << test << " front of container is " << mycontainer.front()
            << " back of container is " << mycontainer.back() << endl;

    cout << "mycontainer size is " << mycontainer.length() << endl;

    cout << "\nTesting the clear() function: \n";
    mycontainer.clear();
    cout << "mycontainer size now is " << mycontainer.length()
            << " mycontainer is empty: "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");


    cout << "\nTesting assignment operator: container2 = mycontainer\n";
    cout << "Filling mycontainer with ints starting at 42\n";
    size = 5;
    // Fill mycontainer with ints to test copy constructor
    for (int i = 0; i < size; i++) {
        mycontainer.enqueue(i + 41);
    }

    cout << "mycontainer size now is " << mycontainer.length()
            << " mycontainer is empty: "
            << (mycontainer.isEmpty() ? " true\n" : "false\n");

    PriorityQueue<int> container2;
    container2 = mycontainer;
    cout << "mycontainer size is: " << mycontainer.length() << endl;
    cout << "container2 size is: " << container2.length() << endl;
    cout << "Testing the contents of container2 and mycontainer using back() and pop_back() functions:\n";
    size = container2.length();
    for (int i = 0; i < size; i++) {
        cout << "Attempting front and pop functions. Iteration: " << i + 1 << "\n";

//.........这里部分代码省略.........
开发者ID:Program0,项目名称:ZerothMarlo_CSC17C,代码行数:101,代码来源:main.cpp


注:本文中的PriorityQueue::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。