From bc5278bdb5daf90d508b7ebe189cec0cd741e36f Mon Sep 17 00:00:00 2001 From: Rakshit Raj Date: Fri, 6 Nov 2020 01:24:38 +0530 Subject: [PATCH] Update count_inversions.cpp - fixed template error on line 156 - an added test case for character array - an added test case for list type double --- sorting/count_inversions.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sorting/count_inversions.cpp b/sorting/count_inversions.cpp index a0ed20f31..ff54a87e4 100644 --- a/sorting/count_inversions.cpp +++ b/sorting/count_inversions.cpp @@ -153,7 +153,7 @@ int mergeSort(T* arr, T* temp, int left, int right) { * @returns number of inversions in input array, sorts the array */ template -int countInversion(T* arr, const T size) { +int countInversion(T* arr, const int size) { std::vector temp; temp.reserve(size); temp.assign(size, 0); @@ -203,11 +203,18 @@ void test() { int result2 = sorting::inversion::countInversion(arr2.data(), size2); assert(inv_count2 == result2); // Test 3 - std::vector arr3 = {33, 45, 65, 76, 1, 2, 5, 7, 88, 12}; + std::vector arr3 = {33.1, 45.2, 65.4, 76.5, 1.0, 2.9, 5.4, 7.7, 88.9, 12.4}; int size3 = arr3.size(); int inv_count3 = 21; int result3 = sorting::inversion::countInversion(arr3.data(), size3); assert(inv_count3 == result3); + // Test 4 + std::vector arr4 = {'a', 'b', 'c', 'd', 'e'}; + int size4 = arr4.size(); + int inv_count4 = 0; + int result4 = sorting::inversion::countInversion(arr4.data(), size4); + assert(inv_count4 == result4); + } // /**