Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Bubble Sort Pada Java

Berikut merupakan program untuk melakukan pengurutan menggunakan Metode SORT pada Java

class latsort{
	public static void main(String Arg[]){

	int bil[] = new int[10];
	int temp ;
	int j,i,n=10 ;
	bil[0] = 50 ;
	bil[1] = 80 ;
	bil[2] = 90 ;
	bil[3] = 50 ;
	bil[4] = 40 ;
	bil[5] = 65 ;
	bil[6] = 60 ;
	bil[7] = 65 ;
	bil[8] = 58 ;
	bil[9] = 10 ;

	System.out.print ("Nilai Sebelum : " );

	for(i=0 ; i < n ; i++)
		System.out.print (bil[i] + "  " );

	for(i = 0 ; i < n ; i++) {
		for(j = n-1 ; j >= i+1 ; j--) {

			if (bil[j] = bil[j-1]){
				temp = bil[j] ;
				bil[j] = bil[j-1] ;
				bil[j-1] = temp ;
			}
		}
	}

	System.out.print ("\nNilai Setelah di urut : ") ;
	for(i=0 ; i < n ; i++)
		System.out.print (bil[i] +  "  " ) ;

	}
}

Hasilnya :

Advertisements

Filed under: Algoritma, Java 2 SE, ,

Terima kasih telah memberikan komentar anda.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives Per Tahun

Sponsored

C&C Online Shop

Blog Stats

  • 367,563 sejak 12 Jan 2011

User’s Online


My Music

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 223 other followers

May 2011
M T W T F S S
« Apr   Jun »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
%d bloggers like this: