Advertisement
Serafim_

Функции в с++

Oct 26th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7.  
  8. void swapl(int &a,int &b){
  9.        int c=a;
  10.        a=b;
  11.        b=c;
  12. }
  13.  
  14.  
  15.  
  16. void print(int a[] ,int n ){
  17.     for (int i = 0; i < n; i++) {
  18.             cout<<a[i]<<"  ";
  19.         }
  20.     cout << endl;
  21. }
  22.  
  23. void bubble_sort(int a[] ,int n ){
  24.     for (int i=0; i<n; i++){
  25.        for (int j=0; j<n-1-i; j++) {
  26.            if (a[j]>a[j+1]){
  27.                swapl(a[j],a[j+1]);
  28.  
  29.            }
  30.         }
  31.     }
  32. }
  33.  
  34.  
  35.  
  36.  
  37. int main()
  38.  
  39. {
  40.  
  41.     int n=5;
  42.     int a[]={3,1,2,4,5};
  43.     print(a,n);
  44.     bubble_sort (a,n);
  45.     print(a,n);
  46.     return 0;
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement