zoukankan      html  css  js  c++  java
  • 我的快速排序

        private void quickSort(int[] arr,int begin,int end)            
        {                                                              
          if(begin>=end)                                               
              return ;                                                 
                                                                       
          int low=begin;                                               
          int high=end;                                                
                                                                       
          int index=begin;                                             
          int temp=arr[begin];                                         
          boolean flag=false;//当flag的值为true向前,否则向后                     
          while(low!=high)                                             
          {                                                            
              if(flag)                                                 
              {                                                        
                  for(;low<high;low++)                                 
                  {                                                    
                      if(arr[low]>temp)                                
                      {                                                
                          arr[high]=arr[low];                          
                          high--;                                      
                          index=low;                                   
                          flag=false;                                  
                          break;                                       
                      }                                                
                  }                                                    
              }                                                        
              else                                                     
              {                                                        
                  for(;high>low;high--)                                
                  {                                                    
                      if(arr[high]<temp)                               
                      {                                                
                          arr[low]=arr[high];                          
                          low++;                                       
                          index=high;                                  
                          flag=true;                                   
                          break;                                       
                      }                                                
                  }                                                    
              }                                                        
          }                                                            
          arr[high]=temp;                                              
          if(high==low)                                                
          {                                                            
              quickSort(arr,begin,high-1);                             
              quickSort(arr,high+1,end);                               
          }                                                            
                                                                       
       }                                                               
        @Test                                                          
        public void testquicksort()                                    
        {                                                              
            int[] arr={49,38,65,97,76,13,27,49};                       
            quickSort(arr, 0, arr.length-1);                           
            for (int i = 0; i < arr.length; i++) {                     
                System.out.print(arr[i]+"  ");                         
                                                                       
            }                                                          
        }                                                              
  • 相关阅读:
    django项目的setting、views(视图文件)、urls(新增子路由)和templates文件
    django问题之2:'set' object is not reversible
    django问题之1:ModuleNotFoundError: No module named 'views'
    搭建django环境和简单的开发post、get接口(转载)
    python中的装饰器原理和作用(转载)
    博客园特效(爱心效果、烟花效果、鼠标吸附粒子/斜杆)
    正则表达式的笔记
    第三方支付的测试点【杭州多测师】【杭州多测师_王sir】
    Python题目【杭州多测师】【杭州多测师_王sir】
    查看Nginx是否启动
  • 原文地址:https://www.cnblogs.com/passer1991/p/2711307.html
Copyright © 2011-2022 走看看