Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void sw(int a, int b)
- {
- a=a+b;
- b=a-b;
- a=a-b;
- }
- void bubble_sort(int array[], int array_length)
- {
- for (int end_condition; end_condition<5; end_condition=0 ){
- for ( int i=1; i<array_length; i++ )
- {
- if ( array[i-1]>array[i])
- {
- sw(array[i-1], array[i]);
- }
- else
- {end_condition++;}
- }
- }
- }
- int main()
- {
- const int l=5;
- int length=l;
- int tab[l]={7,8,1,12,15};
- bubble_sort(tab, 5);
- for (int i=0; i<5; i++)
- {
- cout << tab[i] <<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement