SRC 二分插入代码
来源:互联网 发布:java报500错误怎么解决 编辑:程序博客网 时间:2024/06/05 21:05
int low = 0;
int high = list.size() - 1;
int mid = 0;
int matchMid = -1;
FightRequestReq matchFightRequestReq = null;
while (low <= high) {
mid = (low + high) >>> 1;
int midVal = list.get(mid).getCompetitionVo().getFightValue();
if (midVal >= req.getCompetitionVo().getPrefixValue() && midVal <= req.getCompetitionVo().getSuffixValue()) {
// 匹配成功
if (matchFightRequestReq == null) {
matchFightRequestReq = list.get(mid);
matchMid = mid;
} else {
if (Math.abs(midVal - req.getCompetitionVo().getFightValue()) < Math.abs(matchFightRequestReq.getCompetitionVo().getFightValue() - req.getCompetitionVo().getFightValue())) {
// 匹配到更接近的值
matchFightRequestReq = list.get(mid);
matchMid = mid;
} else {
// 非最优值,继续匹配
}
}
}
if (midVal < req.getCompetitionVo().getFightValue()) {
low = mid + 1;
if (low > high) {
if (midVal < req.getCompetitionVo().getPrefixValue() || midVal > req.getCompetitionVo().getSuffixValue()) {
if (matchFightRequestReq != null) {
return list.remove(matchMid);
} else {
return null;
}
} else {
if (matchFightRequestReq != null) {
if (Math.abs(midVal - req.getCompetitionVo().getFightValue()) < Math.abs(matchFightRequestReq.getCompetitionVo().getFightValue() - req.getCompetitionVo().getFightValue())) {
// 匹配到更接近的值
return list.remove(mid);
} else {
return list.remove(matchMid);
}
} else {
return list.remove(mid);
}
}
}
} else if (midVal > req.getCompetitionVo().getFightValue()) {
high = mid - 1;
if (low > high) {
if (midVal < req.getCompetitionVo().getPrefixValue() || midVal > req.getCompetitionVo().getSuffixValue()) {
if (matchFightRequestReq != null) {
return list.remove(matchMid);
} else {
return null;
}
} else {
if (matchFightRequestReq != null) {
if (Math.abs(midVal - req.getCompetitionVo().getFightValue()) < Math.abs(matchFightRequestReq.getCompetitionVo().getFightValue() - req.getCompetitionVo().getFightValue())) {
// 匹配到更接近的值
return list.remove(mid);
} else {
return list.remove(matchMid);
}
} else {
return list.remove(mid);
}
}
}
} else {
return list.remove(mid);
}
}
if (matchFightRequestReq != null) {
return list.remove(matchMid);
}
return null;
int high = list.size() - 1;
int mid = 0;
int matchMid = -1;
FightRequestReq matchFightRequestReq = null;
while (low <= high) {
mid = (low + high) >>> 1;
int midVal = list.get(mid).getCompetitionVo().getFightValue();
if (midVal >= req.getCompetitionVo().getPrefixValue() && midVal <= req.getCompetitionVo().getSuffixValue()) {
// 匹配成功
if (matchFightRequestReq == null) {
matchFightRequestReq = list.get(mid);
matchMid = mid;
} else {
if (Math.abs(midVal - req.getCompetitionVo().getFightValue()) < Math.abs(matchFightRequestReq.getCompetitionVo().getFightValue() - req.getCompetitionVo().getFightValue())) {
// 匹配到更接近的值
matchFightRequestReq = list.get(mid);
matchMid = mid;
} else {
// 非最优值,继续匹配
}
}
}
if (midVal < req.getCompetitionVo().getFightValue()) {
low = mid + 1;
if (low > high) {
if (midVal < req.getCompetitionVo().getPrefixValue() || midVal > req.getCompetitionVo().getSuffixValue()) {
if (matchFightRequestReq != null) {
return list.remove(matchMid);
} else {
return null;
}
} else {
if (matchFightRequestReq != null) {
if (Math.abs(midVal - req.getCompetitionVo().getFightValue()) < Math.abs(matchFightRequestReq.getCompetitionVo().getFightValue() - req.getCompetitionVo().getFightValue())) {
// 匹配到更接近的值
return list.remove(mid);
} else {
return list.remove(matchMid);
}
} else {
return list.remove(mid);
}
}
}
} else if (midVal > req.getCompetitionVo().getFightValue()) {
high = mid - 1;
if (low > high) {
if (midVal < req.getCompetitionVo().getPrefixValue() || midVal > req.getCompetitionVo().getSuffixValue()) {
if (matchFightRequestReq != null) {
return list.remove(matchMid);
} else {
return null;
}
} else {
if (matchFightRequestReq != null) {
if (Math.abs(midVal - req.getCompetitionVo().getFightValue()) < Math.abs(matchFightRequestReq.getCompetitionVo().getFightValue() - req.getCompetitionVo().getFightValue())) {
// 匹配到更接近的值
return list.remove(mid);
} else {
return list.remove(matchMid);
}
} else {
return list.remove(mid);
}
}
}
} else {
return list.remove(mid);
}
}
if (matchFightRequestReq != null) {
return list.remove(matchMid);
}
return null;
0 0
- SRC 二分插入代码
- 折半二分插入排序Java代码
- 二分插入
- 二分插入
- 二分插入
- 插入排序(解析及代码实现 二分优化)
- 冒泡 选择 插入排序 二分查找 代码备忘
- 插入排序加二分排序详细讲解(附代码)
- 插入类------二分插入排序
- 插入排序 二分插入排序
- 插入排序-二分插入排序
- JS改变图片src代码
- 插入算法(直接插入,二分插入,希尔)
- 二分插入排序
- 二分插入排序。
- bisect模块二分插入
- 二分插入排序
- 二分查找和插入
- asp.net网站利用VS进行简易打包
- iOS 之 PJSIP 笔记(一) 编译多平台支持的静态库
- Web服务器和CGI的关系
- 黑马程序员——第12天——多线程(2/2)
- 黑马程序员——由排序算法引发的代码抽取
- SRC 二分插入代码
- Delphi 通过BDE进行数据库编程
- C语言itoa()函数和atoi()函数详解(整数转字符C实现)
- 关于IOS推送声音的设置
- GitHub中README.md语法解读
- linux vim配置
- eclipse设置和优化
- Android性能测试工具之APT - gether
- NSTimer的一些用法