zoukankan      html  css  js  c++  java
  • 双向排序比较

    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;
    }
    }

    想的都是好
  • 相关阅读:
    JetBrains 里不为人知的秘密(2)--快捷键篇
    phpstorm 2017之输入法
    JetBrains 里不为人知的秘密
    Windows Server 2012 远程连接
    visibility和display的区别
    【dp】摘花生
    【dp】 背包问题
    【dp】求最长公共子序列
    【dp】合唱队形
    【dp】友好城市
  • 原文地址:https://www.cnblogs.com/freezone/p/4920070.html
Copyright © 2011-2022 走看看