jump to navigation

Mengurutkan Data Secara Ascending Dan Descending December 1, 2011

Posted by kelompok24itbseamolecb5 in Algoritma dan Struktur Data.
trackback

1. Mengurutkan Data Secara Ascending

Source Code :

public class Ascending {
public static void main(String args[]) {
int x[] = {3, 7, 5, 9, 2};
int pos, temp, j;
for (int i = 0; i < x.length; i++) {
pos = i;
for (j = i + 1; j < x.length; j++) {
if (x[j] < x[i]) {
pos = j;
}
}
if (pos != i) {
temp = x[i];
x[i] = x[pos];
x[pos] = temp;
}
}
for (int i = 0; i < x.length; i++) {
System.out.print(x[i] + ” “);
}
}
}

 

2. Mengurutkan Data Secara Descending

Source Code :

public class Descanding {
public static void main(String args[]) {
int x[] = {3, 7, 5, 9, 2};
int pos, temp, j;
System.out.println(“Data : 3 7 5 9 2”);
for (int i = 0; i < x.length; i++) {
pos = i;
for (j = i + 1; j < x.length; j++) {
if (x[i] < x[j]) {
pos = j;
}
}
if (pos != i) {
temp = x[i];
x[i] = x[pos];
x[pos] = temp;
}
}
System.out.println(“Hasilnya :”);
for (int i = 0; i < x.length; i++) {
System.out.print(x[i] + ” “);
}
}
}

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: