Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Шпоры по МПиПА / Массивы / Сортировка / Сортировка методом пузырька / C / Исходник / bubbleSort
.cpp#include "iostream.h"
#include "stdio.h"
void bubbleSort(int array[], int col){
int temp=0;
for (int i=1; i<col ; i++){
for (int j=0; j<col-i; j++){
if (array [j]>array [j+1]){
temp=array[j];
array [j]=array [j+1];
array [j+1]=temp;
}
}
}
}
void main(){
int i, size;
int *array;
cout << "Bubble Sort.\nEnter array dimension: ";
cin >> size;
array = new int[size];
cout << "Enter " << size << " elements: ";
for ( i = 0; i < size; i ++ ){
cin >> array[i];
}
bubbleSort( array, size );
cout << "Your array after sorting: ";
for ( i = 0; i < size; i ++ ){
cout << array[i] << " ";
}
cout << "\nPress \"Enter\" to continue..." << endl;
getchar();
}