双向排序比较
2015-10-29 12:06
309 查看
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;
}
}
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;
}
}
相关文章推荐
- Android中Activity常用功能设置小结(包括全屏、横竖屏等)
- JAVA泛型——逆变
- ubuntu 14 安装 tmux 1.6
- 记录-div绝对定位针对手机浏览器的区别
- KEIL中启动文件详解(汇编语言)
- 流水账[0]
- android-仿iOS弹出框
- 在windows操作系统下安装linux
- Leetcode || Roman to Integer
- Objective-c学习笔记之集合
- ios开发弹框提示(适配系统7,8,9)
- 重复ip(单词计数)不同语言实现对比
- OOD软件架构设计原则
- 数组和集合的区别
- myBatis获取批量插入数据的主键id
- SQL语句执行顺序详解
- Android中Touch事件分发过程全解析
- 因滚动条出现而导致页面晃动的解决方案
- Linux系统下findmnt命令使用全解
- vector<string>转换为char*[]