Contoh 1.1 Source Code Java Selection Sort: Public Class Int Public

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

F -X C h a n ge F -X C h a n ge

PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
CONTOH 1.1 SOURCE CODE JAVA { SELECTION SORT}
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

public class selectionSort {


int [] angka= {5, 1, 12, -5, 16, 2, 12, 14};
public selectionSort()

tampilkanAngka ();
urutkanAngka ();
tampilkanAngka ();

void tampilkanAngka () {

System.out.println("\n--------------------------------");
for (int i=0;i<angka.length;i++)
{
System.out.print(angka[i]+" ");
}

void urutkanAngka() {

int tampung;

for (int i=0 ;i<angka.length-1; i++)


{
int minindek=i;
for(int j=i+1; j<angka.length; j++)
{
if(angka[j]<angka[minindek])
minindek=j;

if(minindek!=i){

tampung= angka[i];
angka[i]= angka[minindek];
angka[minindek]= tampung;
}

} //tampilkanAngka();

public static void main(String[] aksi)

{
selectionSort urut = new selectionSort();

}
F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
CONTOH 1.2 SOURCE CODE JAVA { SELECTION SORT}
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Public class SelectionShort {

Public class static void main ( string [] args ) {

Int pos, temp;

Int n = 0;

Int nilai [] = { 44, 55, 12, 42, 94, 18, 06, 67};

For (int i = 0; i<n; i++) {

Pos=i;

For ( int j=1; j<n ; j++){

If ( nilai [j] <nilai [pos] ){

Pos=j;

If ( pos !=1 ) {

Temp = nilai [pos];

Nilai [pos] = nilai [i];

Nilai [i] = temp;

System.out.print(“hasil= “);

For ( int i=0; i<n; i++ )

System.out.print(“ “ + nilai [i]);

System.out.println(“ “);

You might also like