Weight ranking (java) Q: We go to restaurants to queue up for equal number meals, up to 100 tables a day, and the queue number that these 100 tables get will not be repeated (1-100). If the call is not answered for a while, the guests will be postponed to three tables. If there are many delays, it will be difficult for hotels to rank accurately according to the queue number, so how to ensure that the ranking is always correct?
Clue: Instead of queue number sorting, we expand the weight (queue number * capacity = weight) that depends on the sorting number to find out the weights of the guests who count two tables back whenever the guests are delayed. On this basis, +1, so that even if each table is delayed, we can ensure that the sorting by weight is not disorderly.
import java.util.ArrayList; import java.util.List; public class WeightSort { public void Test(){ List<Integer> voList = new ArrayList(); for(int i=0; i < 30; i++){ voList.add(i); } Integer QuqueStatus = 10; Integer getWeightResult = this.updateWaitQueue(voList,QuqueStatus); System.out.println(getWeightResult); } private Integer updateWaitQueue(List<Integer> voList,Integer QuqueStatus) { int FirstMiss = 10; //Get an ordered set of appoId List<Integer> appoIdList = new ArrayList(); for(int i=0; i < voList.size(); i++){ appoIdList.add(voList.get(i)); } Integer nowDOAppId = 1; Integer nowIndex = appoIdList.indexOf(nowDOAppId); Integer targetIndex = null; if(FirstMiss==QuqueStatus){ if(nowIndex == voList.size() - 1){ targetIndex = nowIndex + 1; } else{ targetIndex = nowIndex + 2; } } Integer getWeightResult =0; // if(voList.size() != 1 && null != targetIndex){ getWeightResult = this.getNewWeight(targetIndex); } return getWeightResult; } //Add weight private Integer getNewWeight(Integer targetIndex){ //Elimination of parameter checking Integer nowNewWeight = targetIndex ++; return nowNewWeight; } }