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 ...
随机推荐
- PyTorch学习笔记之n-gram模型实现
import torch import torch.nn as nn from torch.autograd import Variable import torch.nn.functional as ...
- javascript --- 对象之间的继承
了解这一章之前,先把我们之前讲到的以构造函数创建对象为前提的继承抛到一边. 首先,我们先用一个var o = {}创建一个没有任何属性的空对象作为我们的‘画板’,然互在逐步向这个画板里添加属性,和方法 ...
- Oracle SOA Suit Adapter
SOA架构的一个核心的使命是整合企业现存的各式各样的计算资源,它不仅仅是代码层面的整合,更是硬件,计算能力,服务能力的整合.Oracle SOA Suite在这方面做得特别的贴切,它提供了一组Adap ...
- 浮窗WindowManager view返回和Home按键事件监听
出于功能需求,需要在所有的view之上显示浮窗,于是需要在WindowManager的View上处理返回键的响应, mFloatingWindowView = layoutInflater.infla ...
- tensorflow提示出错'module' object has no attribute 'pack'
编译旧的代码,会像下面这样提示出错: deconv_shape3 = tf.pack([shape[0], shape[1], shape[2], NUM_OF_CLASSESS]) Attribut ...
- 编写Web Serviceclient訪问www.webxml.com.cn提供的服务
好久没更新博客了,近期各种忙. 之前做Web Service课程的作业,当中有一个实验.实验内容如题所看到的. 以下简单说下怎样编写Web Serviceclient訪问webxml.com.cn里的 ...
- Opencv 图片边缘检测和最小外接矩形
#include "core/core.hpp" #include "highgui/highgui.hpp" #include "imgproc/i ...
- CMake - boost - 可运行程序 - 静态库
CMake - boost 最后更新日期:2014-04-25by kagula 阅读前提:<CMake入门(二)>.Linux的基本操作 环境: Windows 8.1 64bit英文版 ...
- redis cmd 使用样例
Redis 命令參考 一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15 ...
- mysql: 关于MySQL InnoDB锁行还是锁表?
baidu zone - 关于MYSQL Innodb 锁行还是锁表,深入讲解