Advertisement
CosminVarlan

Untitled

Dec 14th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n=10;
  8.     int a[10] = {5,3,8,1,2,9,6,4,0,7};
  9.  
  10.  
  11.  
  12.  
  13.     // cu selection sort:
  14.     for(int i=0; i<n-1; i++)
  15.         for(int j=i+1; j<n; j++)
  16.         if (a[i]>a[j])
  17.         {
  18.             int aux = a[i];
  19.             a[i]=a[j];
  20.             a[j]=aux;
  21.         }
  22.  
  23.  
  24.     // cu bubble sort;
  25.     int schimbare=1;
  26.     while(schimbare==1)
  27.     {
  28.         schimbare = 0;
  29.         for(int i=0; i<n-1; i++)
  30.             if (a[i]>a[i+1])
  31.             {
  32.                 int aux = a[i];
  33.                 a[i]=a[i+1];
  34.                 a[i+1]=aux;
  35.                 schimbare=1;
  36.             }
  37.     }
  38.  
  39.  
  40.     for(int i=0; i<n; i++)
  41.         cout << a[i] << " ";
  42.  
  43.  
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement