Пример #1
0
int main(int argc, char *argv[])
{
    DLList<scalar> myList;

    for (int i = 0; i<10; i++)
    {
        myList.append(1.3*i);
    }

    myList.append(100.3);
    myList.append(500.3);

    Info<< nl << "And again using STL iterator: " << nl << endl;

    forAllIter(DLList<scalar>, myList, iter)
    {
        Info<< "element:" << *iter << endl;
    }


    Info<< nl << "And again using the same STL iterator: " << nl << endl;

    forAllIter(DLList<scalar>, myList, iter)
    {
        Info<< "Removing " << myList.remove(iter) << endl;
    }
Пример #2
0
int main()
{
    using namespace std;

    
    DLList<int> myIntDLL;

    cout << "Prepending: 5" << endl;
    myIntDLL.prepend(5);
    myIntDLL.printList();

    cout << "Prepending: 4" << endl;
    myIntDLL.prepend(4);
    myIntDLL.printList();

    cout << "Prepending: 3" << endl;
    myIntDLL.prepend(3);
    myIntDLL.printList();
    
    cout << "Appending: 9" << endl;
    myIntDLL.append(9);
    myIntDLL.printList();

    cout << "Appending: 8" << endl;
    myIntDLL.append(8);
    myIntDLL.printList();

    cout << "Appeding: 7" << endl;
    myIntDLL.append(7);
    myIntDLL.printList();

    cout << "Current data: " << *myIntDLL.getValue() << endl;

    cout << "Moving to end" << endl;
    myIntDLL.moveToEnd();
    cout << "Current data: " << *myIntDLL.getValue() << endl;

    cout << "Moving to start" << endl;
    myIntDLL.moveToStart();
    cout << "Current data: " << *myIntDLL.getValue() << endl;

    cout << "Iterating through list with next function" << endl;
    for (int i = 0; i < 10; i++)
    {
        cout << "Current data: " << *myIntDLL.getValue() << endl;
        cout << "Next: " << myIntDLL.next() << endl;
    }

    cout << "Iterating through list with prev function" << endl;
    for (int i = 0; i < 10; i++)
    {
        cout << "Current data: " << *myIntDLL.getValue() << endl;
        cout << "Prev: " << myIntDLL.prev() << endl;
    }

    cout << "Number of links active: " << myIntDLL.numActive() << endl;
    cout << "Number of links free: " << myIntDLL.numFree() << endl;

    cout << "Clearing list" << endl;
    myIntDLL.clear();
    myIntDLL.printList();

    cout << "Number of links active: " << myIntDLL.numActive() << endl;
    cout << "Number of links free: " << myIntDLL.numFree() << endl;
    return 0;
}