#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(int i,int j){return (i>j);}

int main ()
{
    unsigned int i;
    int myints[] = {4,2,6,8,1,9,23,52,3,104,88,7,71};
    vector<int> aVec (myints, myints + sizeof(myints) / sizeof(int) );
    cout<<endl;
    cout<<"+--------------------------------------------------------+"<<endl;
    cout<<"|   Program obrazujacy dzialanie algorytmu nth_element   |"<<endl;
    cout<<"| przykład mediana nieparzystego ciagu liczb całkowitych |"<<endl;
    cout<<"+--------------------------------------------------------+"<<endl;
    cout<<"Tworzymy wektor int i pokazujemy jego ELEMENTY"<<endl;
    for (i=0; i < aVec.size(); i++)
		cout << aVec[i] <<" ";
    cout << endl<<endl;
    cout<<"---------------------------CZESC 1---------------------------"<<endl;
    cout<<"Tworzymy iterator nth i wywolujemy metode nth_element dla standardowej relacji '<'"<<endl;
    vector<int>::iterator nth = aVec.begin() + (sizeof(myints) / sizeof(int)-1)/2;
    nth_element(aVec.begin(), nth, aVec.end());
    cout<<"wektor po metodzie nth_element(3 argumenty iteratory)"<<endl;
    for (i=0; i < aVec.size(); i++)
		cout << aVec[i] <<" ";
    cout << endl;
    cout << "Mediana to: " << *nth << endl;
    cout << endl;
    cout<<"---------------------------CZESC 2---------------------------"<<endl;
    cout<<"wywyolujemy metode nth_element dla relacji odwrotnej przechowywanej w funkcji comp(int,int)"<<endl;
    nth_element(aVec.begin(), nth, aVec.end(),comp);
    cout<<"wektor po metodzie nth_element(4 argumenty 3 x iteratory + funkcja porownawcza)"<<endl;
    for (i=0; i < aVec.size(); i++)
		cout << aVec[i] << " ";
    cout << endl;
    cout << "Mediana to " << *nth << endl;
    cout << endl;
    return 0;
}
