java bubble sort

sort

From this time, I will post about sorting.

Bubble sort

BubbleSort.java


public class BubbleSort {
	public static void sort(int[] array) {
		for(int i=0;i<array.length;i++) {
			for (int j=0;j<array.length-1;j++) {
				if(array[j]>array[j+1]) {
					int temp = array[j];
					array[j] = array[j+1];
					array[j+1] = temp;
				}
			}
		}
	}
	public static void main(String args[]) {
		int[] array = {5,4,3,2,1};
		sort(array);
		for(int i=0;i<array.length;i++) {
			System.out.print(array[i]);
		}
	}
}

This time I tried bubble sort. Next time I will post a selection sort.

Recommended Posts

java bubble sort
Bubble sort using ArrayList (JAVA)
java selection sort
java insertion sort
[java] sort in list
Java Japanese (Kanji) Sort
[Neta] Sleep Sort in Java
Sort strings functionally with java
Java
Java
Java List Group, Sort, etc.
Sorting in ascending order in Java (bubble sort: simple exchange algorithm)
Sort a List of Java objects
Java learning (0)
Studying Java ―― 3
[Java] array
[Java] Annotation
[Java] Module
Java array
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Make bubble sort and selection sort in Ruby
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
[Java] Write a sort faster than Arrays.sort
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Sort by multiple conditions using Java Stream
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance