C++ bubble sort
void printArray17(int *arr, int len) { for (int i = 0; i < len; i++) { cout << arr[i] << "\t"; } cout << endl << endl; } void getArray16(int *arr, int len) { srand(time(NULL)); for (int i = 0; i < len; i++) { arr[i] = rand(); } } void bublleSort22(int len) { int *arr = new int[len]; getArray16(arr, len); cout << "Before bubble sort:" << endl; printArray17(arr, len); cout << "After bubble sort:" << endl; bubbleSort21(arr, len); printArray17(arr, len); delete[] arr; cout << getTimeNow2() << ",finished in void bublleSort22(int len)!!!" << endl << endl; } void bubbleSort21(int *arr, int len) { for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (arr[i] > arr[j]) { swap(&arr[i], &arr[j]); } } } }
g++ -g -std=c++2a -I. *.cpp -o h1 -luuid -lpthread
./h1 100