• 我的快速排序


        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]+"  ");                         
                                                                       
            }                                                          
        }                                                              
  • 相关阅读:
    如何应对“需求不确定型项目”?
    Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED
    R语言之——字符串处理函数
    你看那个人他像一条狗
    BZOJ 3744: Gty的妹子序列 [分块]
    BZOJ 3731 3731: Gty的超级妹子树 [树上size分块 !]
    BZOJ 3720: Gty的妹子树 [树上size分块]
    BZOJ 4129: Haruna’s Breakfast [树上莫队 分块]
    SPOJ COT2 Count on a tree II [树上莫队]
    【WC2013】糖果公园 [树上莫队]
  • 原文地址:https://www.cnblogs.com/passer1991/p/2711307.html
Copyright © 2020-2023  润新知