C++ program to use LIST Standard Template Library (STL)

//program to insert ten numbers
//and sort them in an order (descending)

#include <iostream>
#include <list>
using namespace std;
int main()
{
    list<int> l;

    l.push_back(100);
    l.push_back(23);
    l.push_back(66);
    l.push_back(12);
    l.push_back(99);
    l.push_back(1);
    l.push_back(55);
    l.push_back(89);
    l.push_back(66);
    l.push_back(91);

    l.sort();

    while(!l.empty())
    {
        cout<<l.back()<<endl;
//for ascending.... l.front();
        l.pop_back(); //for ascending...... l.pop_front();
    }
    return 0;
}

No comments:

Post a Comment