Thursday, January 20, 2011

Urut data array dengan metode Bubble Sort

CALL InputVectorDariRandom(X,N)
document.write" Metode pengurutan data dengan Bubble Sort
"
document.write "
"
CALL Cetak(x,n," Sebelum Sorting :")
CALL StandardBubbleSort(x,n)
CALL Cetak(x,n," Setelah Sorting :")

SUB InputVectorDariRandom(byRef v(), byRef N)
RANDOMIZE
N = cint(InputBox("Masukkan Jumlah Elemen Array"))
REDIM v(N)
FOR c=1 TO N
v(c)=10+int(rnd*90)
NEXT
END SUB

SUB StandardBubbleSort(byRef v(), byVal jumlah)
FOR i=1 TO jumlah-1
FOR j=1 TO jumlah-I
IF v(j)>v(j+1) THEN
temp=v(j)
v(j)=v(j+1)
v(j+1)=temp
END IF
NEXT
NEXT
END SUB

SUB Cetak(byVal v(), byVal N, message)
document.write "Isi Vektor " & message & "
"
FOR c=1 TO N
document.write v(c) & ", "
NEXT
document.write "
"
document.write "
"
END SUB

No comments:

Post a Comment