Advertisement
Guest User

ss

a guest
Apr 30th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. void sw(int a, int b)
  8. {
  9. a=a+b;
  10. b=a-b;
  11. a=a-b;
  12. }
  13.  
  14.  
  15.  
  16. void bubble_sort(int array[], int array_length)
  17. {
  18.  
  19. for (int end_condition; end_condition<5; end_condition=0 ){
  20. for ( int i=1; i<array_length; i++ )
  21. {
  22.  
  23. if ( array[i-1]>array[i])
  24. {
  25. sw(array[i-1], array[i]);
  26. }
  27. else
  28. {end_condition++;}
  29. }
  30. }
  31.  
  32. }
  33.  
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39. const int l=5;
  40. int length=l;
  41. int tab[l]={7,8,1,12,15};
  42.  
  43. bubble_sort(tab, 5);
  44.  
  45. for (int i=0; i<5; i++)
  46. {
  47. cout << tab[i] <<" ";
  48. }
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement