Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Bubble_Sort here.
- *
- * @Samuel Berkat Hulu
- * @version 5.0
- */
- import java.util.Scanner;
- public class Bubble_Sort
- {
- static void bubbleSort(int[] arraytest)
- {
- int n = arraytest.length;
- int temp = 0;
- for(int i = 0; i < n; i++)
- {
- for(int j = 1; j < (n-i); j++)
- {
- if(arraytest[j-1] > arraytest[j])
- {
- temp = arraytest[j-1];
- arraytest[j-1] = arraytest[j];
- arraytest[j] = temp;
- }
- }
- }
- }
- public static void main(String[] args)
- {
- int arraytest[] = {2,10,6,40,70,35,29,9,523,234,900,102,400};
- System.out.println("Array sebelum Bubble Sort");
- for(int i=0; i<arraytest.length; i++)
- {
- System.out.print(arraytest[i] + " ");
- }
- System.out.println();
- bubbleSort(arraytest);
- System.out.println("Array sesudah Bubble Sort");
- for(int i=0; i<arraytest.length; i++){
- System.out.print(arraytest[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement