smarkles 0 Newbie Poster

This is our assignment:An STL List Container that adds at least 5 elementes, display i order, and reverse. That part I've got. I'm still doing research on the write to, store ina file and read from a file. Any help would be appreciated. Thanks Smarkles.

#include<iostream>

using namespace std;

#include<list>
#include<algorithm>

template < class T >
void printList ( const std::list< T > &listRef );

int main()
{
    const int SIZE = 5;
    int array[ SIZE ] = { 6,7,8,9,10};

    std::list< int > values;
    std::list< int > otherValues;

    values.push_front( 1 );
    values.push_front( 2);
    values.push_back( 5 );
    values.push_back( 4 );
    values.push_back ( 3 );

    cout << "values contains: ";
    printList( values );

    values.sort();

    cout << "\nvalues after sorting: ";
    printList(values );

    values.reverse();

    cout << "\nValues after reversing: ";
    printList ( values );

    cout  << endl;

    return 0;
}
template < class T >
void printList( const std::list< T > &listRef )
{
    if (listRef.empty() )
        cout << "List is empty";
    else
    {
        std::ostream_iterator< T > output(cout, " " );
        std::copy( listRef.begin(), listRef.end(), output );
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.