Big O(n^2) Ascending Sort | C++

November 15th, 2020 02:05:00 AM

					
#include <iostream> using namespace std; int main() { int dataEntry; int arr[5]; for(int i = 0; i < 5; i++) { cout << "Enter a number that you want to put into the array: "; cin >> dataEntry; arr[i] = dataEntry; } cout << endl; for(int i = 0; i < 5; i++) { cout << "Outputting array info at position " << i + 1 << ": " << arr[i] << endl; } for(int i=0;i<5;i++) { for(int j=i+1;j<5;j++) { if(arr[i]>arr[j]) { int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } cout << endl; for(int i = 0; i < 5; i++) { cout << "Outputting sorted array info at position " << i + 1 << ": " << arr[i] << endl; } return 0; }

Featured Posts