首页 > 其他 > 详细

20165215 MySort的实现

时间:2018-05-20 23:42:39      阅读:131      评论:0      收藏:0      [点我收藏+]

MySort的实现

  • 模拟实现Linux下Sort -t : -k 2的功能。
  • 要有伪代码,产品代码,测试代码(注意测试用例的设计)

代码

package week12;
import java.util.*;
import java.lang.Integer;
public class MySort{
    public static void main(String [] args){
        String [] toSort = {"aaa:10:1:1",
                "ccc:30:3:4",
                "bbb:50:4:5",
                "ddd:20:5:3",
                "eee:40:2:20"};
        System.out.println("Before sort:");
         for (String str: toSort)
            System.out.println(str);
        int [] k3 = new int[toSort.length];
        for (int i = 0; i < toSort.length; i++){
            String [] tmp = toSort[i].split(":");
            k3[i] = Integer.parseInt(tmp[1]);
        }
        Arrays.sort(k3);
        System.out.println("After sort:");
        for (int i = 0; i < k3.length; i++)
            for (int j = 0; j < toSort.length; j++)
              if(k3[i]==Integer.parseInt((toSort[j].split(":"))[1]))
                    System.out.println(toSort[j]);
    }
}

运行结果

技术分享图片

20165215 MySort的实现

原文:https://www.cnblogs.com/fyss/p/9065173.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!