package com.paixu;
class shuzu{
int length;
int r[] = new int[100];
//创建数组
public void create(int a[]){
for (int i = 0;i<=length;i++){
r[i] = a[i];
}
}
//展示数组
public void display(){
System.out.println("这里是展示数组:");
for (int i = 1;i<=length;i++){
System.out.print(r[i]+" ");
}
System.out.println();
}
//冒泡排序
public void maopao_paixu(){
int i,j,temp;
for (i = 1;i<=length;i++){
for (j = i+1;j<=length;j++){
if (r[i]>r[j]){
temp = r[i];
r[i] = r[j];
r[j] =temp;
}
}
}
System.out.print("冒泡排序后,");
}
//选择排序
public void xuanze_paixu(){
int i,j,min_,temp;
for (i = 1;i<=length;i++){
min_ = i;
for (j = i+1;j<=length;j++){
if (r[min_]>r[j]){
min_ = j;
}
}
if (i!=min_){
temp = r[i];
r[i] = r[min_];
r[min_] = temp;
}
}
System.out.print("选择排序后,");
}
//插入排序
public void charu_paixu(){
int i,j;
for (i=2;i<=length;i++){
if (r[i]<r[i-1]){
r[0] = r[i];
for (j = i-1;r[j]>r[0];j--){
r[j+1] = r[j];
}
r[j+1] = r[0];
}
}
System.out.print("插入排序后,");
}
}
public class paixu {
public static void main(String[] args) {
// TODO Auto-generated method stub
shuzu sz = new shuzu();
sz.length = 10;
int a[] = {0,5,8,9,7,22,20,16,200,65,98};
sz.create(a);
sz.display();
sz.maopao_paixu();
sz.display();
}
}