GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaRock/src/main/java/com/test/basic/array/BubbleSort.java at master · wyx-98/JavaRock

Expand file tree

/

BubbleSort.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
32 lines (31 loc) · 1.11 KB
/

BubbleSort.java

Copy path

File metadata and controls

32 lines (31 loc) · 1.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.test.basic.array;
/**
* Created by beigui on 2016/3/7.
* 功能:冒泡排序 从小到大排
* 思路:相邻两个数比较,左边比右边大则交换,整体比较完毕是一次排序
* 这样的排序要进行n-1趟
*/
public class BubbleSort {
public static void main(String[] args) {
int[] array = new int[]{63, 4, 24, 1, 3, 13};
System.out.println("冒泡排序法从小到大排序的过程是:");
//i是趟数
for (int i = 1; i < array.length; i++) {
//j是一趟中比较次数
for (int j = 0; j < array.length - i; j++) {
if (array[j] > array[j + 1]) {
//swap
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
System.out.print(array[j] + " ");
}
System.out.print("【");
for (int j = array.length - i; j < array.length; j++) {
System.out.print(array[j] + " ");
}
System.out.println("】");
}
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.