26 lines
555 B
C++
26 lines
555 B
C++
|
#include <iostream>
|
||
|
#include <ostream>
|
||
|
using namespace std;
|
||
|
|
||
|
void bubbleSort(int *array, int length) {
|
||
|
int i, j, temp;
|
||
|
for(i = length - 1; i > 0; i--) {
|
||
|
for(j = 0; j < i; j++) {
|
||
|
if(array[j] > array[j+1]) {
|
||
|
temp = array[j];
|
||
|
array[j] = array[j+1];
|
||
|
array[j+1] = temp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
int array[10] = {7,9,1,2,3,6,4,5,8,0};
|
||
|
bubbleSort(array,10);
|
||
|
|
||
|
for (int i=0; i < 10; i++) {
|
||
|
cout << array[i] << " ";
|
||
|
}
|
||
|
cout << endl;
|
||
|
}
|