No Kegiatan Dan Latihan Script Bubble Sorting
No Kegiatan Dan Latihan Script Bubble Sorting
No Kegiatan Dan Latihan Script Bubble Sorting
No Script
dan Latihan
Bubble public class BubbleSort {
void bubbleSort(int arr[]) {
Sorting
System.out.println("Bubble Sorting");
System.out.print("Data Sebelum di Sorting : ");
for(int x = 0; x < 5; x++)
System.out.print(arr[x]+" ");
int n = arr.length;
for (int i = 0; i < n-1; i++)
Buatlah for (int j = 0; j < n-i-1; j++)
Proses if (arr[j] > arr[j+1]) {
sorting dan int temp = arr[j];
jumlah data arr[j] = arr[j+1];
arr[j+1] = temp;
sesuai }
dengan }
akhiran
1. void printArray(int arr[]) {
NIM
int n = arr.length;
for (int i=0; i<n; ++i)
Catatan: System.out.print(arr[i] + " ");
nilai yang System.out.println();
diinputkan }
random dan
public static void main(String args[]) {
akhiran nim BubbleSort ob = new BubbleSort();
0,1,2,3,4 di int arr[] = {64, 34, 15, 12, 22};
tambah 10 ob.bubbleSort(arr);
System.out.println("");
System.out.print("Data Setelah di Sorting : ");
ob.printArray(arr);
}
}
2. Quick public class QuickSort {
public static void quickSort(int[] input) {
Sorting
int n=input.length;
qsort(input,0,n-1);
}
if(s>=e)
return;
int a=input[s];
int count=s;
for(int i=s+1;i<=e;i++) {
if(input[i]<=a)
count++;
}
input[s]=input[count];
input[count]=a;
int i=s;
int j=e;
while(i<=count && j>=count) {
if(input[i]<=a)
i++;
else {
if(input[j]<=a) {
int temp=input[j];
input[j]=input[i];
input[i]=temp;
i++;
j--;
}
else
j--;
}
}
qsort(input,s,count-1);
qsort(input,count+1,e);
}
System.out.println();
}
int i = 0, j = 0;
int k = left;
while (i < n1 && j < n2) {
if (Left[i] <= Right[j]) {
arr[k] = Left[i];
i++;
}
else {
arr[k] = Right[j];
j++;
}
k++;
}
if (largest != i) {
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;
heapify(arr, n, largest);
}
}
int outPos = 0;
for (int p = 0; p < bucket.length; p++) {
for (int q = 0; q < bucket[p]; q++) {
array[outPos++] = p;
}
}
}
return max;
}