For example, say I have [7, 11, 0, 2], I want to compare 7 and 2, then 11 and 0.
Two ways I have done this so far by entering the positions in statements like this:
list[0] > list[list.length-1] then list[1] > list[list.length-2], I obviously don’t want to have to type all this manually as my lists get larger. Another way I tried to test how to do this was with a recursion but because my program is already running in a recursion I found it a bit confusing..so is it possible to dynamically compare items against each other without the use of a recursion?
The list size is always even and fixed for the life of the program. Any ideas?
note: If I get the idea I can implement it myself but specifically what I’m doing is comparing if each relative item is larger than the other and if they are equal then I compare the next item. For example, [1,5,3,1,5,1], I would compare 1 & 1 and since they are the same I would move to compare 5 & 5 and since they are the same I’d compare 3 & 1. Not sure if there’s a non-recusive way to do it, but thought I’d try.
I had to do something similar when checking for palindromes in strings