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. dprobe and dprofile

    https://github.com/xwlan dprofiler Lightweight CPU Memory I/O and Lock profiler for Windows dprobe D ...

  2. iOS -- SKPhysicsWorld类

    SKPhysicsWorld类 继承自 NSObject 符合 NSCodingNSObject(NSObject) 框架  /System/Library/Frameworks/SpriteKit. ...

  3. Opencv 最小外接矩形合并拼接

    前一篇画出了最小外接矩形,但是有时候画出来的矩形由于中间像素干扰或者是其他原因矩形框并不是真正想要的 如图1是一个信号的雨图,被矩形框分割成了多个小框: 需要合并矩形框达到的效果: 主要思想: 扫描两 ...

  4. [Algorithm] Write a Depth First Search Algorithm for Graphs in JavaScript

    Depth first search is a graph search algorithm that starts at one node and uses recursion to travel ...

  5. Ural 2018The Debut Album(DP)

    题目地址:Ural 2018 简单DP.用滚动数组. 代码例如以下: #include <iostream> #include <cstdio> #include <st ...

  6. 【Spark】RDD操作具体解释4——Action算子

    本质上在Actions算子中通过SparkContext运行提交作业的runJob操作,触发了RDD DAG的运行. 依据Action算子的输出空间将Action算子进行分类:无输出. HDFS. S ...

  7. 理解MySql事务隔离机制、锁以及各种锁协议

    一直以来对数据库的事务隔离机制的理解总是停留在表面,其内容也是看一遍忘一边.这两天决定从原理上理解它,整理成自己的知识.查阅资料的过程中发现好多零碎的概念假设串起来足够写一本书,所以在这里给自己梳理一 ...

  8. Node.js 数据存储方式的选择

    如何为你的 Node.js 应用挑选数据库 Node.js 应用一般有三种方式保存数据. 不使用任何数据库管理系统(DBMS),把数据保存在内存里或直接使用文件系统. 使用关系数据库.例如 MySQL ...

  9. Ubuntu 登陆异常-输入正确的密码后还会返回到登陆界面的问题

    问题表现: 启动到了登陆界面,输入对应的密码,发现一闪黑屏有返回到登陆界面,如此往复. 解决方法: 开机后在登陆界面按下shift + ctrl + F1进入tty命令行终端登陆,可以查看用户主目录下 ...

  10. 使用Python与数据库交互

    # -*- coding: utf-8 -*- """ Created on Sun Nov 18 19:25:01 2018 @author: wangm " ...