* NIM : 208533420031
* M.K. : AlgoritMa dan Struktur Data
* Praktek : (A) Membuat Program Pengurutan (Sort) dan Pencarian (Searching)
* No. Nama Buah
* -------------------------------
* 1. mangga
* 2. anggur
* 3. jeruk
* 4. salak
* 5. dukuh
* 6. apel
* 7. manggis
* 8. kiwi
* 9. nangka
* 10. belimbing
********************* ------------------------------- *************************/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Pengurutan
{
private static int ukuranVector;
public static String Arr [] = new String [5];
public static void main(String[] args)
{
System.out.print("Berapa Data yang Anda mau masukkan? ");
ukuranVector = inputData();
InsertArray();
BubbleSort();
Search();
}
private static int inputData() {
BufferedReader bfr = new BufferedReader(
new InputStreamReader(System.in));
String angkaInput = null;
try {
angkaInput = bfr.readLine();
} catch (IOException e) {
e.printStackTrace();
}
int Data = Integer.valueOf(angkaInput).intValue();
return Data;
}
public static String DataString()
{
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
String StringInput = null;
try {StringInput = bfr.readLine();}
catch (IOException e)
{ e.printStackTrace(); }
return StringInput;
}
public static void InsertArray()
{
for(int x = 0; x
{
System.out.print("Masukkan data Array ke "+x+" : ");
Arr[x] = DataString();
}
}
public static void BubbleSort()
{
System.out.println("*=============================================*");
System.out.println("* data terurut dengan Metoda BUBBLE SORT *");
System.out.println("*=============================================*");
for (int y=0; y < Arr.length; y++)
{
for (int x = y + 1; x < Arr.length; x++)
{
if (Arr[x].compareTo(Arr[y]) < 0)
{
String t = Arr[y];
Arr[y] = Arr[x];
Arr[x] = t;
}
}
System.out.println("Data ke "+y+" : "+Arr[y]);
}
}
private static void Search()
{
System.out.print("Masukkan data yang Anda cari : ");
String cari = DataString();
for (int x= 0; x
{
if (Arr[x].equals(cari))
{
System.out.println();
System.out.println("Data "+cari+" ada dalam Index ke "+x);
}
}
}
}
Tidak ada komentar:
Posting Komentar