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的更多相关文章

  1. greedy algorithm, insertion sort, quick sort

    always makes the choice that seems to be the best at that moment. Example #1: @function:  scheduling ...

  2. [LintCode] Sort List 链表排序

    Sort a linked list in O(n log n) time using constant space complexity. Have you met this question in ...

  3. Bucket Sort

    (referrence: GeekforGeeks) Bucket sort is mainly useful when input is uniformly distributed over a r ...

  4. 总结: Sort 排序算法

    排序总结 面试经验 硅谷某前沿小Startup面试时,问到的一个题目就是写一个快速排序算法.进而面试官问到了各种算法的算法复杂度,进而又问了Merge Sort 与 QuickSort 的优劣. 对排 ...

  5. STL sort

    STL的sort()算法,数据量大时采用Quick Sort,分段递归排序,一旦分段后的数据量小于某个门槛,为避免Quick Sort的递归调用带来过大的额外负荷,就改用Insertion Sort. ...

  6. STL sort源码剖析

    转载自:http://www.cnblogs.com/imAkaka/articles/2407877.html STL的sort()算法,数据量大时采用Quick Sort,分段递归排序,一旦分段后 ...

  7. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  8. 1306. Sorting Algorithm 2016 12 30

    1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...

  9. JAVA排序算法

    ];  ; i <  ; i++){ sort[i] = ran.nextInt(); } System.out.print(;i<sort.length;i++){ ;j<sort ...

随机推荐

  1. spring springmvc js websocket 监听

    第一步:web.xml中支持异步.所有的filter及servlet <filter> <filter-name>characterEncoding</filter-na ...

  2. Android 获取设备唯一标识码

    概述 有时需要对用户设备进行标识,所以希望能够得到一个稳定可靠并且唯一的识别码.虽然Android系统中提供了这样设备识别码,但是由于Android系统版本.厂商定制系统中的Bug等限制,稳定性和唯一 ...

  3. R语言数据分析系列之五

    R语言数据分析系列之五 -- by comaple.zhang 本节来讨论一下R语言的基本图形展示,先来看一张效果图吧. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi ...

  4. jquery+css 实现即时变化颜色主题(通过input输入颜色值进行改变)

    实现效果需要自行导入jquery.js <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  5. Eoeclient源代码分析---SlidingMenu的使用

    Eoeclient源代码分析及代码凝视 使用滑动菜单SlidingMenu,单击滑动菜单的不同选项,能够通过ViewPager和PagerIndicator显示相应的数据内容. 0  BaseSlid ...

  6. mqtt client python example

    This is a simple example showing how to use the [Paho MQTT Python client](https://eclipse.org/paho/c ...

  7. inch mil mm换算

    inch:英寸 mil:密耳 mm:毫米 1mil=0.0254mm=25.4um 1mm=39.37mil 1inch=1000mil=25.4mm

  8. WPF01(xaml)

    XAML:(转自http://www.cnblogs.com/huangxincheng/archive/2012/06/17/2552511.html) <Window x:Class=&qu ...

  9. 不使用flash实现复制文字(图片)到剪贴板

    <div>这里是待复制的文字或图片</div> var range = document.createRange(); var referenceNode = document ...

  10. 使用 fcntl 函数 获取,设置文件的状态标志

    前言 当打开一个文件的时候,我们需要指定打开文件的模式( 只读,只写等 ).那么在程序中如何获取,修改这个文件的状态标志呢?本文将告诉你如何用 fcntl函数 获取指定文件的状态标志. 解决思路 1. ...