zoukankan      html  css  js  c++  java
  • java面试准备之基础排序——冒泡与选择排序

    选择排序: 
     
     
    [java]  
     
    public void select(int[] arr){  
     
            for(int i=0;i<arr.length;i++){  
     
                for(int j=i+1;j<arr.length;j++){  
     
                    if(arr[j]>arr[i]){  
     
                        int one = arr[i];  
     
                        arr[i]=arr[j];  
     
                        arr[j]=one;  
     
                    }  
     
                }  
     
                  
     
            }  
     
              
     
        }  
     
     
     
    冒泡排序:
     
     
     
    [java]  
     
    public static int[] popo(int[] arr){  
     
            for(int i=0;i<arr.length-1;i++){  
     
                for(int j=1,k=0;j<arr.length-i;j++,k++){  
     
                    if(arr[k]>arr[j]){  
     
                        int one = arr[k];  
     
                        arr[k]=arr[j];  
     
                        arr[j]=one;  
     
                    }  
     
                      
     
                }  
     
            }  
     
            for(int i=0;i<arr.length;i++){  
     
                  
     
                System.out.print(arr[i]+" ");  
     
            }  
     
            return arr;  
     
        } 

    http://www.cnblogs.com/xiaohukuaipao/p/3674469.html

  • 相关阅读:
    Linux02--文件系统与磁盘管理
    Android02-Activity01
    Android01-概述
    LeetCode | Binary Tree Level Order Traversal II
    LeetCode | Binary Tree Level Order Traversal
    LeetCode | Binary Tree Postorder Traversal
    LeetCode | Binary Tree Inorder Traversal
    LeetCode | Binary Tree Preorder Traversal
    LeetCode | Symmetric Tree
    LeetCode | Balanced Binary Tree
  • 原文地址:https://www.cnblogs.com/azhqiang/p/3674719.html
Copyright © 2011-2022 走看看