Profile image for Dominic Charley-Roy jokeofweek
This is an implementation of a basic bubble sort on an array of integers.
Language
Java
Tags
algorithm arrays bubble sort

Bubble Sort

1 public class BubbleSort { 2 3 4 public static int[] sort(int[] arr) 5 { 6 boolean swapped=false; 7 int temp =0; 8 9 do { 10 swapped=false; 11 for (int i=0;i < (arr.length-1);i++) 12 { 13 if (arr[i] > arr[i+1]) { 14 temp=arr[i+1]; 15 arr[i+1]=arr[i]; 16 arr[i]=temp; 17 swapped=true; 18 } 19 } 20 21 } while (swapped); 22 23 return arr; 24 } 25 }

Comments