/*选择排序*/
package SelectionSort; import java.util.Arrays; public class SelectionSort { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] m_Num={7,9,0,1,3,2,9,4,9,7,3,8,9,4,3,8,5,6}; int m_Lenght=m_Num.length; int tmpNum=0; for(int i =0;i<m_Lenght-1;i++){ for(int j=i+1;j<m_Lenght;j++){ if(m_Num[j]>m_Num[i]){ tmpNum=m_Num[i]; m_Num[i]=m_Num[j]; m_Num[j]=tmpNum; } } } String tmpNumSort=Arrays.toString(m_Num); System.out.println(tmpNumSort); } }
/*冒泡排序*/
package BubbleSort; import java.util.Arrays; import java.util.Scanner; public class BubbleSort { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner m_NumSort=new Scanner(System.in); int[] m_Num={}; System.out.println("请输入需排列的整数数组"); do { m_Num=Arrays.copyOf(m_Num, m_Num.length+1); m_Num[m_Num.length-1]=m_NumSort.nextInt(); // System.out.println(Arrays.toString(m_Num)); } while (m_Num[m_Num.length-1]!=99); System.out.println("there"); Sort(m_Num); m_NumSort.close(); } private static void Sort(int[]aNum){ int tmp; for(int i=0;i<aNum.length-1;i++){ for(int j=0;j<aNum.length-(i+1);j++){ if(aNum[j]>aNum[j+1]){ tmp=aNum[j]; aNum[j]=aNum[j+1]; aNum[j+1]=tmp; System.out.println("here"); } } } String tmpNumSort=Arrays.toString(aNum); System.out.println(tmpNumSort); } }
/*插入排序*/
package InsertSort; import java.util.Arrays; import java.util.Scanner; public class InsertSort { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner m_InputNum=new Scanner(System.in); int[] m_Num={}; System.out.println("请输入排序的整数数组:"); do { m_Num=Arrays.copyOf(m_Num, m_Num.length+1); m_Num[m_Num.length-1]=m_InputNum.nextInt(); } while (m_Num[m_Num.length-1]!=99); System.out.println(Arrays.toString(m_Num)); Sort(m_Num); m_InputNum.close(); } private static void Sort(int[] aNum){ int tmp; int tmpINum; for(int i=1;i<aNum.length;i++){ for(int j=i-1;j>=0;j--){ if((aNum[i]>=aNum[j])&&aNum[i]<=aNum[j+1]){ tmp=aNum[i]; tmpINum=i; while(j!=tmpINum-1){ aNum[tmpINum]=aNum[tmpINum-1]; tmpINum--; } aNum[j+1]=tmp; break; } } } System.out.println(Arrays.toString(aNum)); } }