From 3a0af23bdee53016c377abca3fa38e1129d71c6d Mon Sep 17 00:00:00 2001 From: MarcUs7i Date: Wed, 7 May 2025 18:20:12 +0200 Subject: [PATCH] Added sorting criteria --- sorting_criteria.c | 22 ++++++++++++++++++++++ sorting_criteria.h | 7 ++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/sorting_criteria.c b/sorting_criteria.c index c093e44..3190c88 100644 --- a/sorting_criteria.c +++ b/sorting_criteria.c @@ -11,3 +11,25 @@ */ #include "sorting_criteria.h" + +/** + * Determines whether or not `fst` is smaller than or equal to `snd` (ascending order). + * + * @param fst The value that is supposed being smaller than `snd`. + * @param snd The value to compare. + * @return True if `fst` is smaller than or equal to `snd`, false otherwise. + */ +bool is_in_asc_order(int fst, int snd) { + return fst <= snd; +} + +/** + * Determines whether or not `fst` is greater than or equal to `snd` (descending order). + * + * @param fst The value that is supposed being greater than `snd`. + * @param snd The value to compare. + * @return True if `fst` is greater than or equal to `snd`, false otherwise. + */ +bool is_in_desc_order(int fst, int snd) { + return fst >= snd; +} diff --git a/sorting_criteria.h b/sorting_criteria.h index eb1f8ad..ef82848 100644 --- a/sorting_criteria.h +++ b/sorting_criteria.h @@ -27,6 +27,7 @@ * (the values are in order), false otherwise. */ /* Note: Name the pointer type 'criterion_fn' */ +typedef bool (*criterion_fn)(int fst, int snd); /** * Determines whether or not `fst` is smaller than or equal to `snd` (ascending order). @@ -35,15 +36,15 @@ * @param snd The value to compare. * @return True if the criterion is satisfied, false otherwise. */ -bool is_in_asc_order(); +bool is_in_asc_order(int fst, int snd); /** * Determines whether or not `fst` is larger than or equal to `snd` (descending order). * - * @param fst The value that is supposed being smaller than `snd`. + * @param fst The value that is supposed being greater than `snd`. * @param snd The value to compare. * @return True if the criterion is satisfied, false otherwise. */ -bool is_in_desc_order(i); +bool is_in_desc_order(int fst, int snd); #endif \ No newline at end of file