用到的人会理解此描述,不多说直接上代码
public class maxtest { public static void main(String[] args) { //###################二维极点start###################// String[] ewjd = {"2,4","5,3","15,7","3,10","10,6","6,8","8,2","13,5","13,7"}; List listewjd = new ArrayList(); String newewjd; for (int j = 0; j < ewjd.length-1; j++) { for (int i = 0; i < ewjd.length; i++) { if(ewjd.length-1 == i){ break; }else{ String[] split = ewjd[i].split(","); String[] split2 = ewjd[i+1].split(","); if(Integer.parseInt(split[0]) > Integer.parseInt(split2[0])){ newewjd = ewjd[i]; ewjd[i] = ewjd[i+1]; ewjd[i+1] = newewjd; } } } } for (int i = 0; i < ewjd.length; i++) { listewjd.add(ewjd[i]); } System.out.println(jddg(listewjd,1)); //###################二维极点start###################// } //二维极点递归 public static List jddg (List listewjd,int start){ if (start == 1) { start = 0 ; for (int i = listewjd.size()-1; i >= 0; i--) { if(0 == i){ break; }else{ String[] split = listewjd.get(i).toString().split(","); String[] split2 = listewjd.get(i-1).toString().split(","); if(Integer.parseInt(split[1]) >= Integer.parseInt(split2[1])){ listewjd.remove(i-1); start = 1; } } } jddg(listewjd,start); } return listewjd; }}
结果如下:
[3,10, 6,8, 15,7]