Interesting! Looks like a human bubble sort routine with which you push the highest ranked item to the end of the file. For my understanding, is this a ranking system for music songs or favorite holiday destinations? Well, never mind, your problem is that you pick two items randomly. Is there any reason for? If not you should do as follows (suppose you have 10 items):
- present items 1 and 2, ask for ranking and switch them if necessary
- then present items 2 and 3 and ask again (and switch again)
- then present items 3 and 4 and ask again (and switch again)
- and so on until you have presented (and maybe switched) items 9 and 10
Now, the highest ranked item is at place 10. So in the next ranking round do the same as stated above, BUT stop at presenting item 8 and 9 since item 10 already is ranked correctly. In the next round you stop at 7+8, then at 6+7, until you only have to present items 1 and 2. Good luck!