mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Fix for loop formatiing
This commit is contained in:
commit
7af31e32a2
@ -51,9 +51,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
/** \brief
|
/** \brief
|
||||||
* Insertion Sort Function
|
* Insertion Sort Function
|
||||||
@ -76,41 +76,41 @@ void insertionSort(int *arr, int n) {
|
|||||||
|
|
||||||
/** Test Cases to test algorithm */
|
/** Test Cases to test algorithm */
|
||||||
void tests() {
|
void tests() {
|
||||||
int arr1[10] = { 78, 34, 35, 6, 34, 56, 3, 56, 2, 4};
|
int arr1[10] = {78, 34, 35, 6, 34, 56, 3, 56, 2, 4};
|
||||||
insertionSort(arr1, 10);
|
insertionSort(arr1, 10);
|
||||||
assert(std::is_sorted(arr1, arr1 + 10));
|
assert(std::is_sorted(arr1, arr1 + 10));
|
||||||
std::cout << "Test 1 Passed" << std::endl;
|
std::cout << "Test 1 Passed" << std::endl;
|
||||||
|
|
||||||
int arr2[5] = {5, -3, 7, -2, 1};
|
int arr2[5] = {5, -3, 7, -2, 1};
|
||||||
insertionSort(arr2, 5);
|
insertionSort(arr2, 5);
|
||||||
assert(std::is_sorted(arr2, arr2 + 5));
|
assert(std::is_sorted(arr2, arr2 + 5));
|
||||||
std::cout << "Test 2 Passed" << std::endl;
|
std::cout << "Test 2 Passed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Main Function */
|
/** Main Function */
|
||||||
int main() {
|
int main() {
|
||||||
/// Running predefined tests to test algorithm
|
/// Running predefined tests to test algorithm
|
||||||
tests();
|
tests();
|
||||||
|
|
||||||
/// For user insteraction
|
/// For user insteraction
|
||||||
int n;
|
int n;
|
||||||
std::cout << "Enter the length of your array : ";
|
std::cout << "Enter the length of your array : ";
|
||||||
std::cin >> n;
|
std::cin >> n;
|
||||||
int *arr = new int[n];
|
int *arr = new int[n];
|
||||||
std::cout << "Enter any " << n << " Numbers for Unsorted Array : ";
|
std::cout << "Enter any " << n << " Numbers for Unsorted Array : ";
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
std::cin >> arr[i];
|
std::cin >> arr[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
insertionSort(arr, n);
|
insertionSort(arr, n);
|
||||||
|
|
||||||
std::cout << "\nSorted Array : ";
|
std::cout << "\nSorted Array : ";
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
std::cout << arr[i] << " ";
|
std::cout << arr[i] << " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
delete[] arr;
|
delete[] arr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user