首页 > 代码库 > sort quick
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); } }}
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;}
sort quick
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。