#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>  // Include algorithms
using namespace std;

int main( )
{
    vector<int> V;
    int i, n, temp;
    int j;
    double p, pSwitch;

    srand(5);  // seed the random number generator

    n = 1000;  // n is the number of elements to be sorted

    pSwitch = .1;  // pSwitch is the probability that adjacent
                   // elements should be switched
    

    V.resize (n); 

    // Create a sorted vector
    for (i = 0; i < n; i++) 
       { 
          V[i] = i;
       } 


    // Jumble the vector
    for (i = 0; i < n-1; i++)
       {
          if ( (double(rand()%100)/100) <= pSwitch)
            {
              temp = V[i];
              V[i] = V[i+1];
              V[i+1] = temp;
            }
       }


    cout << "Sort the jumbled vector: " << endl;
    for (i = 0; i < n; i++) 
       { 
           cout << V[i] << " ";
       } 

    cout << endl;

    // Sort the vector V using the Standard Template Library
    // sort() function.

    std::sort(V.begin(),V.end());    

    cout << "The sorted vector is: " << endl;
    for (i = 0; i < n; i++) 
       { 
           cout << V[i] << " ";
       } 

    cout << endl;

}      
