Answer:
private void moveUp(int pos){ for(int i=pos;i<scoreboard.size()-1;i++){ // iterate from pos to end of the array. Player p=scoreboard.get(i); //get the ith player Player t=scoreboard.get(i+1); //get the (i+1) player i.e immediate next player if(p.highScore < t.highScore){ //check if current player highScore < next player highScore scoreboard.set(i+1,p); //just exchange the elements i.e players scoreboard.set(i,t); } } }
Explanation:
Utilities used in the code:-
Following are the methods used in the code above:-
get(index) - This method returns the element at a specific index from the list.
set(index,element) - This method updates a element at specific element to new element.
size() - This method returns the size of the array list.