• 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
  • 相关阅读:
    从员工到总监,你要明白的8个道理!
    IT民工2013的升迁
    你会对老板说这十句傻话吗
    BIO
    同步工具类
    NIO(一)
    Lock与Condition
    forkJoin
    线程池与Future
    今天需要获取一个网站的web服务反馈回来的数据,找到份不错的帖子关于WebClient类的使用,记录下来·
  • 原文地址:https://www.cnblogs.com/feiguo/p/3971956.html
Copyright © 2020-2023  润新知