SHARE
TWEET

ZADOBAL

a guest May 23rd, 2019 58 in 6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. struct tVector{
  8.     int Item[1000];
  9.     int Count;
  10.     int Imax;
  11.     int Imin;
  12.     void Input(int Xn, int Xk);
  13.     void Out();
  14.     void GetMax();
  15.     void GetMin();
  16.     void Sortify();
  17. };
  18.  
  19. void tVector::GetMax(){
  20.     Imax = 1;
  21.     for(int i=0;i<Count;i++){
  22.         if(i != 0 && i != Count-1 && Item[i] > Item[Imax]){
  23.             Imax = i;
  24.         };
  25.     };
  26.     cout<<endl<<"Imax=";
  27.     cout<<Imax<<endl;
  28. }
  29.  
  30. void tVector::GetMin(){
  31.     Imin = 1;
  32.     for(int i=0;i<Count;i++){
  33.         if(i != 0 && i != Count-1 && Item[i] < Item[Imin]){
  34.             Imin = i;
  35.         };
  36.     };
  37.     cout<<endl<<"Imin=";
  38.     cout<<Imin<<endl;
  39. }
  40.  
  41. void tVector::Sortify(){
  42.     int Min, Max, t, MinN;
  43.     GetMin();
  44.     GetMax();
  45.     Min = (Imin<Imax)?Imin:Imax;
  46.     Max = (Imin<Imax)?Imax:Imin;
  47.     for(int i=Min;i<Max;i++){
  48.         MinN = i;
  49. //        cout<<"Now running from "<<MinN<<endl;
  50.         for(int j=i;j<Max+1;j++){
  51.             if(Item[j] < Item[MinN]){
  52. //                cout<<"Item["<<j<<"]("<<Item[j]<<")<"<<"Item["<<MinN<<"]("<<Item[MinN]<<"), swapping..."<<endl;
  53.                 MinN = j;
  54.                 t = Item[i];
  55.                 Item[i] = Item[MinN];
  56.                 Item[MinN] = t;
  57.             };
  58.         };
  59.     };
  60.     Out();
  61. }
  62.  
  63. void tVector::Input(int Xn, int Xk){
  64.     srand(time(0));
  65.     Count=10;
  66.     for(int i=0;i<Count;i++)Item[i]=Xn+rand()%(Xk-Xn+1);
  67.     Out();
  68. }
  69.  
  70. void tVector::Out(){
  71.     cout<<endl;
  72.     for(int i=0;i<Count;i++)cout<<"["<<i<<"]="<<Item[i]<<"\t";
  73.     cout<<endl;
  74. }
  75.  
  76. int main()
  77. {
  78.     tVector X;
  79.     X.Input(0,100);
  80.     cout<<endl<<"================================================="<<endl<<endl;
  81.     X.Sortify();
  82.     return 0;
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top