Thursday, January 20, 2011

Urut data array dengan metode Straight Selection Sort

CALL InputVectorDariRandom(X,N)
document.write" Metode pengurutan data dengan straight selection sort
"
document.write "
"
CALL Cetak(x,n," Sebelum Sorting :")
CALL StraightSelectionSort(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 StraightSelectionSort(byRef v(), byVal N)
FOR i=1 TO N-1
FOR j=i+1 TO N
IF v(i)>v(j) THEN
temp=v(i)
v(i)=v(j)
v(j)=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