⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bubblesort.java

📁 包括冒泡排序
💻 JAVA
字号:
package com.arithmetic;

import java.util.Random;

/**
 * 冒泡排序
 * @author Administrator
 *
 */
public class BubbleSort {

	
	public static void main(String args[]){ 
		long time=0,starttime=0,endtime=0;
		Random r = new Random();
		int length = 80000;
		int[] array = new int[length];
		int n=0;
		for(int i=0;i<length;i++) {
			int x = r.nextInt();
			array[n] = x;
			n++;
		}
/*		System.out.print("排序前:");
		for(int i = 0;i<length;i++){ 
			System.out.print(array[i] + ","); 
			if(i%100==0) {
				System.out.println();
			}
		} 
		System.out.println();*/
//		System.out.print("排序后:");
		BubbleSort b = new BubbleSort();
		starttime = System.currentTimeMillis();
		BubbleSort.bubbleSort(array);//调用函数 
		endtime = System.currentTimeMillis();
		time = endtime-starttime;
		
/*		System.out.print("排序后:");
		for(int i = 0;i<length;i++){ 
			System.out.print(array[i] + ","); 
			if(i%100==0) {
				System.out.println();
			}
		}
		System.out.println();*/
		System.out.println("所用时间:"+time);
	}
	public static void bubbleSort(int a[]){ //函数 
		int temp; 
		int size = a.length; 
		for(int i = size - 1;i>=1;i--){ 
			for(int j = 0;j<i;j++){ 
				if (a[j]>a[j+1]){
				temp = a[j]; 
				a[j] = a[j+1]; 
				a[j+1] = temp; 
				} 
			} 
		} 
	}  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -