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. extern “C”的使用

    2016-12-11   22:40:48 VS编译的时候,可以指定编译为C代码或者C++代码.c/c++->高级.而当你新建一个cpp文件时,VS很有可能自动会把编译方式由C变成C++编译.然 ...

  2. 如何给redis设置密码

    如何给redis设置密码 学习了:https://blog.csdn.net/qq_35357001/article/details/56835919

  3. django 实现下载功能

    from django.http import FileResponse def download(request): if..... file=open([path],'rb') response= ...

  4. C++ 继承与接口 知识点 小结(一)

    [摘要] 要求理解覆盖.重载.隐藏的概念与相互之间的差别.熟记类继承中对象.函数的訪问控制:掌握虚函数.虚函数表.虚函数指针的联系:理解区分虚函数和虚继承在虚方法.虚指针在空间分配上的重点与难点:熟练 ...

  5. C#向Sql数据库插入空值的控制

    string name = textBox1.Text; int age = Convert.ToInt32(textBox2.Text.Trim()); ? null : (int?)Convert ...

  6. Java数据库访问技术

    1.Java集合: Collection Map List: 位于 java.util包中. Arraylist 顺序结构.Linkedlist 链表结构 // List<NewsClassif ...

  7. icmp的程序(ping的实现)

    code来源于<网络编程与分层协议设计> chap7 ICMP协议程序设计 ----没有理解,没有编译,只是敲了出来 ping.h #define ICMP_ECHOREPLY 0#def ...

  8. 网页编程-django前传

    1.js正则表达式  http://www.cnblogs.com/wupeiqi/articles/5602773.html test  - 判断字符串是否符合规定的正则 正则表达式: rep = ...

  9. 详谈kubernetes滚动更新-1

    系列目录 这个系列分为两个小节,第一个小节介绍deployment滚动更新时,deployment.replicaset.pod的细节以及创建过程以及deployment版本管理的方式 第二个小节将介 ...

  10. Spring AOP和IOC(转载)

    spring 的优点?1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3.容器提供单例模式支持 4.容器提供了AOP技术,利用它很容易实 ...