Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package first;
- /**
- *
- * @author admin
- */
- public class First {
- public void bubbleSort(int[] arr) {
- boolean swapped = true;
- while(swapped) {
- swapped = false;
- for(int i = 0; i < arr.length - 1; i++) {
- if(arr[i] > arr[i + 1]) {
- int temp = arr[i];
- arr[i] = arr[i + 1];
- arr[i + 1] = temp;
- swapped = true;
- }
- }
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- First s = new First();
- int[] arr = new int[] {7,2,0,4,5,6,9,1,3,8};
- s.bubbleSort(arr);
- for(int i = 0; i < arr.length; i++) {
- System.out.print(arr[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement