Created
November 6, 2016 06:25
-
-
Save mkdika/1156ae90818234ed7854f9e3624e302e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class BubbleSortString { | |
public static void BubbleSort(String[] arrs) { | |
String temp; | |
System.out.print("Before Sort: "); | |
System.out.println(Arrays.toString(arrs)); | |
for (int i = 0; i < arrs.length - 1; i++) { | |
for (int j = 0; j < arrs.length - 1; j++) { | |
if (arrs[j].compareTo(arrs[j+1])>0 ) { | |
temp = arrs[j]; | |
arrs[j] = arrs[j + 1]; | |
arrs[j + 1] = temp; | |
} | |
} | |
} | |
System.out.print("After Sort : "); | |
System.out.println(Arrays.toString(arrs)); | |
} | |
public static void main(String arg[]) { | |
String[] data = {"Jack Man","Budi Man","Andy Gunawan","Denny Tejo", | |
"Sofyan","Fendy Agus"}; | |
BubbleSort(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment