+ 1

How to create bubble sort in C

how could is happend explain

24th Aug 2018, 3:45 PM
Ronak Paul
Ronak Paul - avatar
2 Respuestas
+ 7
#include <iostream> using namespace std; int main() { int arr[] = {4, 6, 1, 3, 8, 5, 9}; int size = sizeof(arr) / sizeof(arr[0]); //Bubble Sorting Start for(int i = 0; i < size; i++) { for(int j = 0; j < size - 1; j++) { if(arr[j] > arr[j+1]) { int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } //Bubble Sorting End for(int i = 0; i < size; i++) cout << arr[i] << " "; return 0; }
24th Aug 2018, 10:14 PM
blACk sh4d0w
blACk sh4d0w - avatar
24th Aug 2018, 3:51 PM
Ketan Lalcheta
Ketan Lalcheta - avatar