package request.http.com.httprequest.activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initData();
}
private void initData(){
int [] bubble = {45,34,23,56,4,5};
BubbleSort(bubble);
for(int i : bubble){
System.out.println("冒泡后的排序=="+ i);
}
}
/**
* 冒泡排序:两个数比较大小,较大的数下沉,较小的数冒出来
*
*/
private void BubbleSort(int [] bubbleArray){
for(int i=0;i<bubbleArray.length-1;i++){
for(int j=0;j<bubbleArray.length-i-1;j++){
//交换位置
if(bubbleArray[j]>bubbleArray[j+1]){
int temp=bubbleArray[j];
bubbleArray[j]=bubbleArray[j+1];
bubbleArray[j+1]=temp;
}
}
}
}
android冒泡排序
最新推荐文章于 2023-10-07 07:00:00 发布