zoukankan      html  css  js  c++  java
  • 20175208 张家华 MySort

    MySort

    注意:研究sort的其他功能,要能改的动代码,需要答辩
    模拟实现Linux下Sort -t : -k 2的功能。
    要有伪代码,产品代码,测试代码(注意测试用例的设计)
    参考 Sort的实现。提交博客链接。

      1 import java.util.*;
      2
      3 public class MySort1 {
      4     public static void main(String [] args) {
      5         String [] toSort = {"aaa:10:1:1",
      6                             "ccc:30:3:4",
      7                             "bbb:50:4:5",
      8                             "ddd:20:5:3",
      9                             "eee:40:2:20"};
     10
     11         System.out.println("Before sort:");
     12         for (String str: toSort)
     13                     System.out.println(str);
     14
     15         Arrays.sort(toSort);
     16
     17         System.out.println("After sort:");
     18         for( String str : toSort)
     19             System.out.println(str);
     20     }
     21 }
    

    实践代码:

    import java.util.*;
    public class Mysort1 {
        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);
        String  [] s1 = new String[toSort.length];
        for (int i = 0; i < toSort.length; i++) {
            String list[] = toSort[i].split(":");
            s1[i] = list[2];
        }
        Arrays.sort(s1);
        String [] s2 = new String[toSort.length];
        for (int i=0; i<s1.length;i++)
            for (int j=0;j<toSort.length;j++)
                if( toSort[j].charAt(7) == (s1[i].toCharArray()[0]))
                    s2[i] = toSort[j];
        System.out.println("After sort:");
        for(String  str : s2 )
            System.out.println(str);
    }
    }
    

    程序截图:

  • 相关阅读:
    一段路
    memcache 键名的命名规则以及和memcached的区别
    浏览器解释网页时乱码
    windows下安装Apache
    巧用PHP数组函数
    程序返回值的数据结构
    Linux如何生成列表
    判断用户密码是否在警告期内(学习练习)
    判断用户的用户名和其基本组的组名是否一致
    sed笔记
  • 原文地址:https://www.cnblogs.com/kaoru/p/10890946.html
Copyright © 2011-2022 走看看