Need explanations on how this code processes Arraylist values

前端 未结 3 1925
迷失自我
迷失自我 2021-01-27 07:00
public static void mystery1(ArrayList list) { 
for (int i = list.size() - 1; i > 0; i--) { 
    if (list.get(i) < list.get(i - 1)) { 
        int el         


        
3条回答
  •  醉话见心
    2021-01-27 07:21

    I think you are forgetting that the loop is going from the end of the list to the beginning. If you take the list you gave as input and follow the process you will get the result [10, 30, 40, 20, 60, 50]. Which is the right one. Just do it in paper and you will see.

提交回复
热议问题