Advertisement
darkjessy94

lab asd lezione6 es1 massimo

Oct 17th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. ///Dato un insieme di N numeri, trovare il k-esimo numero piΓΉ grande
  2.  
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. class Massimo
  9. {
  10. private:
  11.     vector<int> vett;
  12.     int mass=0;
  13. public:
  14.     Massimo(){mass=0;}
  15.     Massimo(vector<int> &vett)
  16.     {
  17.         this->vett=vett;
  18.         Insertion_Sort();
  19.         cout<<"Massimo numero e': "<<maxx()<<endl;
  20.     }
  21.     ~Massimo(){}
  22.  
  23.     void Insertion_Sort()
  24.     {
  25.         int key, i;
  26.         for(int j=1; j < vett.size(); j++)
  27.         {
  28.                 key=vett.at(j);
  29.                 i = j-1;
  30.                 while ( i >= 0 && vett.at(i) > key)
  31.                 {
  32.                     vett.at(i+1)= vett.at(i);
  33.                     i--;
  34.                 }
  35.             vett.at(i+1)=key;
  36.         }
  37.         cout << endl << "Vettore ordinato" << endl;
  38.         // Stampa del vettore ordinato
  39.         for(int j=0; j <vett.size(); j++)
  40.         {
  41.             cout << vett.at(j) <<" ";
  42.         }
  43.  
  44.     }
  45.  
  46.     int maxx(){return vett.at(vett.size()-1);}
  47. };
  48.  
  49. int main()
  50. {
  51.     vector<int> numeri;
  52.     int n=4,tmp;
  53.     for(int i=0;i<n;i++)
  54.     {
  55.         cout<<"Inserisci numero: ";
  56.         cin>>tmp;
  57.         numeri.push_back(tmp);
  58.     }
  59.  
  60.  
  61.     Massimo T(numeri);
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement