• 双向排序比较


    package clean;

    import java.util.ArrayList;
    import java.util.List;


    public class Test_ {

    public static void main(String[] args) {

    //8,10,12
    //8,10,12,13,15,18
    //8,10
    //8,12,13,18
    List<Integer> idList1 = new ArrayList<Integer>();
    idList1.add(8);
    // idList1.add(10);
    idList1.add(12);
    idList1.add(13);
    idList1.add(18);

    //8,10,12,13,15,18
    //8,10,12
    //8,12,13,18
    //8,10
    List<Integer> idList2 = new ArrayList<Integer>();
    idList2.add(8);
    idList2.add(10);
    // idList2.add(12);
    // idList2.add(13);
    // idList2.add(15);
    // idList2.add(18);


    compare(idList1, idList2);
    }


    public static void compare(List<Integer> idList1,List<Integer> idList2){
    int matchCount = 0;
    int notmatchCount_list1 = 0;
    int notmatchCount_list2 = 0;

    long id_list1 = 0;
    long id_list2 = 0;
    int j = 0;
    for(int i = 0; i < idList1.size();i++){
    id_list1 = idList1.get(i);

    if(j == idList2.size()){
    notmatchCount_list1++;
    continue;
    }


    for(; j < idList2.size();j++){
    id_list2 = idList2.get(j);
    if(id_list1 == id_list2){
    matchCount++;

    j++;
    if(i == idList1.size() - 1){
    for(; j < idList2.size();j++){
    notmatchCount_list2++;
    }
    }
    break;
    }else if(id_list1 < id_list2){
    notmatchCount_list1++;
    if(i == idList1.size() - 1){
    notmatchCount_list2++;
    j++;
    for(; j < idList2.size();j++){
    notmatchCount_list2++;
    }
    }

    break;
    }else {
    if(j == idList2.size()-1){
    notmatchCount_list1++;
    }

    notmatchCount_list2++;
    continue;
    }
    }
    }

    System.out.println((matchCount+notmatchCount_list1) == idList1.size());
    System.out.println((matchCount+notmatchCount_list2) == idList2.size());

    matchCount = 0;
    notmatchCount_list1 = 0;
    notmatchCount_list2 = 0;
    }
    }

    想的都是好
  • 相关阅读:
    final和finally的区别
    ArrayList和LinkedList的区别
    collection和collections的区别
    第三次作业
    第二次作业
    第零次作业
    最后一次作业-- 总结报告
    第14、15教学周作业
    GridView去掉边框! 【转载于:http://magicpeng99.blog.sohu.com/】
    ASP.NET支持用Menu显示web.sitemap中定义好的网站链接 【转载】
  • 原文地址:https://www.cnblogs.com/freezone/p/4920070.html
Copyright © 2020-2023  润新知