sorting | Sololearn: Learn to code for FREE!

0

sorting

how to sort(using bubble sort) numbers from smallest to biggest in c++ by for nested in a easy way?

8/18/2018 1:16:35 PM

motahareh

2 Answers

New Answer

+4

#include <iostream> using namespace std; int main() { int arr[] = {5, 2 , 1 , 7 , 9 , 3, 6}; int size = sizeof(arr)/sizeof(arr[0]); 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; } } } for(int i = 0; i < size; i++) cout << arr[i] << " "; return 0; }

+1

https://www.sololearn.com/learn/774/?ref=app