Skip to content

Commit

Permalink
Fix sort_ascend utility function to sort decimals (#25)
Browse files Browse the repository at this point in the history
* refactor[DataTomeAnalysis]!: Optimize Median method from TC O(N log N) to O(N) using IntroSort Algorithm
Median now uses introSelect algorithm merging between quickSelect and medianOfMedians Algorithm
feat[DataTomeUtils]: Adding dt_min helper function to get minimum value between two values and swap to swap two values
resolves (#18)

* fix[DataTomeAnalysis]: renaming min to dt_min to use utility minimum function instead of cpp std lib

* fix:[DataTomeUtils]: Refactoring dt_min utility function

* fix[DataTomeUtils]: Refactor sort_ascend Utility Function to precisely sort decimal numbers

resolves #24
  • Loading branch information
mohammedelgammal authored Dec 27, 2024
1 parent 3f601cb commit 3092fcb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/DataTomeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ int sort_ascend(const void *cmp1, const void *cmp2) {
TypeOfArray b = *((TypeOfArray *)cmp2);
TypeOfArray a = *((TypeOfArray *)cmp1);

return (int)a - b;
if (a > b)
return 1;
else if (a < b)
return -1;
return 0;
}

template <typename TypeOfArray>
Expand All @@ -21,8 +25,8 @@ void swap(TypeOfArray &a, TypeOfArray &b) {
b = temp;
}

template <typename T>
const T &dt_min(const T &a, const T &b) {
template <typename TypeOfArray>
const TypeOfArray &dt_min(const TypeOfArray &a, const TypeOfArray &b) {
return (a < b) ? a : b;
}

Expand Down

0 comments on commit 3092fcb

Please sign in to comment.