From 6d64f5ebacc9c4081624785298a4f4db142664d7 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 26 Jul 2024 01:24:52 +0100 Subject: Added comparators to Fraction struct --- src/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 222cab4..f490d41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,6 +49,19 @@ struct Fraction { } + bool operator<(const Fraction other) + { + if (other.denominator == denominator) + return numerator < other.numerator; + // TODO: Is it better to use the GCD? + return (numerator * other.denominator) < (other.numerator * denominator); + } + + bool operator==(const Fraction &other) + { + return numerator == other.numerator && denominator == other.denominator; + } + void simplify(void) { // No-Op if already simplified -- cgit v1.2.3-13-gbd6f