BubbleSorting

Run Settings
LanguageC++
Language Version
Run Command
#include<iostream> #include<ctime> using namespace std; int main() { srand(time(NULL)); int n; int temp=0; cout << "Enter size array" << endl; cin >> n; int *array = new int[n]; for (int i = 0; i < n; i++) { array[i] = rand() % 20; cout << array[i] << "\t"; } cout << endl; //----------------------------- for (int i = 0; i < n-1; ++i) { for (int j = 0; j < n-1; ++j) { if (array[j+1] < array[j]) { temp = array[j + 1]; array[j + 1] = array[j]; array[j] = temp; } } } cout << "------------------------------------------------------------" << endl; for (int i = 0; i < n; i++) { cout << array[i] << "\t"; } cout << endl; delete[] array; system("Pause"); return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines