Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Dato un insieme di N numeri, trovare il k-esimo numero piΓΉ grande
- #include <iostream>
- #include <vector>
- using namespace std;
- class Massimo
- {
- private:
- vector<int> vett;
- int mass=0;
- public:
- Massimo(){mass=0;}
- Massimo(vector<int> &vett)
- {
- this->vett=vett;
- Insertion_Sort();
- cout<<"Massimo numero e': "<<maxx()<<endl;
- }
- ~Massimo(){}
- void Insertion_Sort()
- {
- int key, i;
- for(int j=1; j < vett.size(); j++)
- {
- key=vett.at(j);
- i = j-1;
- while ( i >= 0 && vett.at(i) > key)
- {
- vett.at(i+1)= vett.at(i);
- i--;
- }
- vett.at(i+1)=key;
- }
- cout << endl << "Vettore ordinato" << endl;
- // Stampa del vettore ordinato
- for(int j=0; j <vett.size(); j++)
- {
- cout << vett.at(j) <<" ";
- }
- }
- int maxx(){return vett.at(vett.size()-1);}
- };
- int main()
- {
- vector<int> numeri;
- int n=4,tmp;
- for(int i=0;i<n;i++)
- {
- cout<<"Inserisci numero: ";
- cin>>tmp;
- numeri.push_back(tmp);
- }
- Massimo T(numeri);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement