Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /*
  8.  * File:   main.cpp
  9.  * Author: roman
  10.  *
  11.  * Created on October 20, 2019, 10:53 AM
  12.  */
  13.  
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <fstream>
  17. #include <string>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include <cmath>
  21. #include <complex>
  22. #include <limits>
  23. #include <algorithm>
  24.  
  25. using namespace std;
  26.  
  27.  
  28. void sort(int * tab, int size){
  29.  
  30.     int i,j,x;
  31.    
  32.     for(i=1; i<size; i++){
  33.         for(j=size; j>=i; j--){  
  34.             if(tab[j-1] > tab[j]){
  35.                 swap(tab[j-1], tab[j]);              
  36.             }
  37.         }
  38.        
  39.     }
  40. }
  41.  
  42. int main(int argc, char** argv) {
  43.    
  44.     int tab[10] {5, 6, 4, -3, 5, 8, 3, 2, 5, 20};
  45.     int size = sizeof(tab)/sizeof(tab[0]);
  46.    
  47.     sort(tab, size);  
  48.    
  49.     for(int i = 0; i<size; i++){
  50.         cout<<tab[i]<<" ";
  51.     }
  52.     cout<<endl;
  53.    
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement