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.