sort quick
package com.demo; import java.util.ArrayList;
import java.util.List; public class SearchSort
{
public List<TestBean> quickSort(List<TestBean> list, int from, int to) {
if (from < to) {
TestBean temp = list.get(to);
int i = from - 1;
for (int j = from; j < to; j++) {
if (compare(list.get(j), temp)) {
i++;
TestBean tempValue = list.get(j);
list.set(j, list.get(i));
list.set(i, tempValue);
}
}
list.set(to, list.get(i+1));
list.set(i+1,temp);
quickSort(list, from, i);
quickSort(list, i + 1, to);
}
return list;
} public boolean compare(TestBean testBean, TestBean temp){ /*
if (testBean.score < temp.score)
return true;
else if(testBean.score == temp.score){
if(testBean.id().compareTo(temp.id())<=0)
return true;
else return false;
}*/
if(testBean.id.compareTo(temp.id) < 0)
{
return true;
}
else
return false;
} public static void main(String[] args)
{
List<TestBean> list = new ArrayList<TestBean>(); TestBean bean = new TestBean();
bean.author = "ninhao";
bean.date = "10101";
bean.id = "2342342341";
bean.score = 3; TestBean bean3 = new TestBean();
bean3.author = "ninhao3";
bean3.date = "10101";
bean3.id = "2342342340";
bean3.score = 4; TestBean bean2 = new TestBean();
bean2.author = "ninha2";
bean2.date = "10101";
bean2.id = "2342342343";
bean2.score = 0; TestBean bean1 = new TestBean();
bean1.author = "ninhao1";
bean1.date = "10101";
bean1.id = "234234";
bean1.score = 2; list.add(bean);
list.add(bean1);
list.add(bean2);
list.add(bean3); System.out.println(list.size());
SearchSort SearchSort =new SearchSort();
list = SearchSort.quickSort(list, 0, list.size()-1); for(TestBean beane : list)
{
System.out.println(beane.score + " " + beane.id + " " +beane.author);
}
} }
test
package com.demo; public class TestBean
{
public String id;
public String title;
public String keywords;
public String describe;
public String date;
public String url;
public String kind;
public String author;
public String publisher;
public String content;
public String height;
public String width;
public String mp4Url;
public String imageUrl;
public int score;
public int num;
}
bean
sort quick的更多相关文章
- greedy algorithm, insertion sort, quick sort
always makes the choice that seems to be the best at that moment. Example #1: @function: scheduling ...
- [LintCode] Sort List 链表排序
Sort a linked list in O(n log n) time using constant space complexity. Have you met this question in ...
- Bucket Sort
(referrence: GeekforGeeks) Bucket sort is mainly useful when input is uniformly distributed over a r ...
- 总结: Sort 排序算法
排序总结 面试经验 硅谷某前沿小Startup面试时,问到的一个题目就是写一个快速排序算法.进而面试官问到了各种算法的算法复杂度,进而又问了Merge Sort 与 QuickSort 的优劣. 对排 ...
- STL sort
STL的sort()算法,数据量大时采用Quick Sort,分段递归排序,一旦分段后的数据量小于某个门槛,为避免Quick Sort的递归调用带来过大的额外负荷,就改用Insertion Sort. ...
- STL sort源码剖析
转载自:http://www.cnblogs.com/imAkaka/articles/2407877.html STL的sort()算法,数据量大时采用Quick Sort,分段递归排序,一旦分段后 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- 1306. Sorting Algorithm 2016 12 30
1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...
- JAVA排序算法
]; ; i < ; i++){ sort[i] = ran.nextInt(); } System.out.print(;i<sort.length;i++){ ;j<sort ...
随机推荐
- PageHelper分页工具
<a>共${page.total}件商品</a> <a>共${page.pages}页</a> <a>当前第${page.pag ...
- javascript好文 --- 深入理解可视区尺寸client
可视区大小 可视区大小client又称为可见大小或客户区大小,指的是元素内容及其内边距所占据的空间大小 clientHeight clientHeight属性返回元素节点的可见高度 clientHei ...
- Linux 软件大全
应用 音频 Airtime - Airtime 是一款用于调度和远程站点管理的开放广播软件 Ardour - 在 Linux 上录音,编辑,和混音 Audacious - 开源音频播放器,按你想 ...
- Failure [INSTALL_FAILED_ALREADY_EXISTS]
1.发生原因 做unity开发的同事说apk无法安装,要我帮忙看下,然后我通过命令adb install安装apk,出现此提示 2.解决过程 首先想到的仍然是安装包已存在的问题,结果使用清理类软件清理 ...
- eclipse从svn检出项目
在eclipse的project explorer 右键->import->svn->从svn检出项目,然后填写资源库的位置,完成,然后一直next. 直到项目检出完成后,选择项目, ...
- MQTT 测试工具介绍
eclipse paho 下载地址为: https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org ...
- java基础&&高薪面试
董鹏老师 ,多年经验总结出 [高薪就业必备]之java基础面试题[更新中]: 第01篇 学习Java基础的目的? 第02天 java语言中有没有gotoke ...
- 我的Android进阶之旅------>Android中android:windowSoftInputMode的使用方法
面试题:怎样在显示某个Activity时马上弹出软键盘? 答案:在AndroidManifest.xml文件里设置<activity>标签的android:windowSoftInputM ...
- alexNet--deep learning--alexNet的11行代码
% Copyright 2016 The MathWorks, Inc. clear camera = webcam( 2 ); % Connect to the camerannet = ale ...
- Python自动生成文章
为了应付某些情况,需要做17份记录.虽然不很重要,但是17份完全雷同也不很好.大体看了一下,此记录大致分为四段.于是决定每段提供四种选项,每段四选一,拼凑成四段文字,存成一个文件.文件名就叫“XX记录 ...