29
u/estragon0 Sep 16 '18
Sure, laugh now; when the integers suddenly stop being a poset you'll be sorry.
2
Sep 17 '18
Integers are not just partially ordered.
3
u/rocketman0739 Sep 17 '18 edited Sep 17 '18
Yeah, but this code could still be redundant if Z were only partially ordered. Like if suddenly -5 became neither greater than, lesser than, nor equal to -3. That wouldn't change the fact that, for an array of nonnegative integers, you don't need to always compare everything.
25
u/Jonno_FTW shameless Sep 17 '18 edited Sep 17 '18
There's just so many additional layers of bad here:
Bad indentation
Can't just return 0 or return 1
Doesn't check for array size 0 or 1
For loop checking status instead of just returning
Nested loop,
Could be one single loop by checking the sign of arr[i] - arr[i+1] against mode
Comment says modes should be 0 or 1, but code is for 0 and anything else
11
13
u/cli7 Sep 16 '18
Actually it is checking if it is in ascending or descending order. Still no reason for double iteration
6
u/KamiKagutsuchi Sep 16 '18
This is awful at so many levels, I dont know where to begin. I'd suggest burning it, but it's not on paper..
3
u/Teoemeka Sep 17 '18
This is the time you want to write it on your own from the beginning rather than refactoring.
4
Sep 16 '18
I am learning about efficient algorithms and complexities and this just hurts to look at. If I wrote code like this for an assignment I would be kicked out of my college.
28
u/WhyYouLetRomneyWin Sep 16 '18
What project is this? It looks like some poor student's homework.