Insertion Sort - dalam bahasa JAVA

berikut untuk source sorting dengan insertion..

public class insertionSort {

public static void tampilkanData(String Nama[],String JK[], int umur[], int indeksTerakhir)
{
for (int i = 0; i <= indeksTerakhir; i++) System.out.println("Nama = "+Nama[i]+ "\tJenisKelamin = "+JK[i]+"\tUmur = "+umur[i]); } public static void urutInsertion(String Nama[],String JK[], int umur[], int indeksTerakhir){ int i, j; String temp =""; for(i=1; i=0 && temp.compareTo(Nama[j]) < 0) { Nama[j+1] = Nama[j]; j = j-1; } Nama[j+1] = temp; } } public static void main(String[] args) { String[] Nama = {"Ardi","Ade","Latief","Anca","Lia"}; String[] JK = {"L","L","L","L","P"}; int[] umur = {23,21,35,28,20}; int indeksTerakhir = Nama.length - 1; System.out.println("Data sebelum diurutkan: "); tampilkanData(Nama,JK,umur, indeksTerakhir); urutInsertion(Nama,JK,umur, indeksTerakhir); System.out.println(""); System.out.println("Data setelah diurutkan: "); tampilkanData(Nama,JK,umur, indeksTerakhir); } }

Comments

Popular posts from this blog

Shenzhen Hi-tec network Technology co. Ltd

Network Technology course

Network Technology book Pdf