#include #include #include #include "time.h" #include using namespace std; int main() { list iList; vector // seed the random number generator srand( (unsigned)time( NULL ) ); // populate the list with 10 rnd ints from 0-99 for (int i = 0; i < 10; ++i) { int rInt = rand() % 10; iList.push_back(rInt); } // display the list list::iterator p; int largest = iList.front(); int smallest = iList.back(); int sum = 0; cout << endl << "Unsorted list" << endl; for (p = iList.begin(); p != iList.end(); ++p) { cout << *p << " "; sum += *p; if (*p < smallest) { smallest = *p; } if (*p > largest) { largest = *p; } } float avg = float(sum) / float( iList.size() ); cout << endl << endl << "Average is " << avg << endl; cout << endl << endl << "Largest is " << largest << " Smallest is " << smallest << endl; iList.sort(); int j; int steps = iList.size() / 2 - 1; for (p = iList.begin(), j = 0; j < steps; ++j) { ++p; } cout << endl << endl << "The median is " << *p; if (iList.size() % 2 == 0 && *p != *(++p) ) { cout << " and " << *p << endl; } iList.unique(); // display sorted, distinct elements cout << endl << "Sorted list, duplicates removed" << endl; for (p = iList.begin(); p != iList.end(); ++p) { cout << *p << " "; } return 0; }