Insertion Operator

Pages: 12
I see what you mean. That actually cuts out a fair amount of code and makes it a lot cleaner. I was making it more complicated than it needed to be. Thank you!
I think your simplify function still won't work if the numbers have multiple factors of the same prime. Try 4/8 as an example. think you'll wind up with 2/4 instead of 1/2.

Besides, your algorithm is less efficient than it needs to be. It should be:
1
2
3
int factor = gcd(abs(numerator), denominator);
numerator /= factor;
denominator /= factor;

Look up code for computing gcd(). It's really fast.
Topic archived. No new replies allowed.
Pages: 12