冒泡排序简单案例(自己写的做个记录)
作者:互联网
import org.junit.Test; public class maopaopaixu { //为什么要来上海工作? //上海的经济发展 //上海的互联网发展 //上海的平台 //上海的环境 public static void main(String[] args) { //从小到大 int arr[]={1,0,3,2,4}; for (int i = 0; i < arr.length-1; i++) { for (int j = 0; j<arr.length-1-i; j++) { if (arr[j]>arr[j+1]) { int temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } for (int i = 0; i<arr.length; i++) { System.out.print(arr[i]+" "); } // 从大到小 int arr1[]={2,0,1,3,4}; for (int i = 0; i < arr1.length-1; i++) { for (int j = 0; j<arr1.length-1-i; j++) { if (arr1[j]<arr1[j+1]) { int temp=arr1[j]; arr1[j]=arr1[j+1]; arr1[j+1]=temp; } } } for (int i = 0; i<arr1.length; i++) { System.out.print(arr1[i]+" "); } } }
标签:arr,temp,记录,int,上海,冒泡排序,案例,public 来源: https://blog.csdn.net/Lyh_ok/article/details/122150049