Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // by abdul fazri ikmi cyber university cirebon
- public static void main(String[] args) {
- int[] tabInt = {7,5,2,1,4,6,10,9,3,8};
- int i,n,temp,tukar;
- n=6;
- //keluarkan data awal
- System.out.println("Data Awal");
- for(i=0;i<n;i++){
- System.out.print(tabInt[i]+ " ");
- }
- //bubble sort
- do{
- tukar = 0;
- for(i=0; i<(n-1); i++){
- if(tabInt[i] > tabInt[i+1]){
- temp = tabInt[i];
- tabInt[i] = tabInt[i+1];
- tabInt[i+1] = temp;
- tukar = 1;
- }
- }
- }while(tukar == 1);
- //keluarkan data terurut
- System.out.println("\nData Terurut");
- for(i=0;i<n;i++){
- System.out.print(tabInt[i]+ " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement