Vous êtes sur la page 1sur 9

LAPORAN TUGAS BESAR

Struktur Data Kelas A

Insertion Sort,Bubble Sort dan Selection Sort

Disusun Oleh:

Mamnuah (1215100001)
Rika Nurhanipah (1215100057 )
Alima Rosyida (1215100063)

JURUSAN MATEMATIKA
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
INSTITUT TEKNOLOGI SEPULUH NOPEMBER

2017
BAB I

DESKRIPSI TUGAS

Tanggal : 03 Mei 2016

Soal no.1 :Membuat progam dan mengimplementasikan Insertion Sort !

Soal no. 2: Membuat progam dan mengimplementasikan Bubble Sort !

Soal no.3 :Membuat progam dan mengimplemetasikan Selection Sort !


BAB II

SOURCE CODE

1. Insertion Sort

package tubes.insertion;

import java.util.Scanner;

public class TUBESINSERTION {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("inisiasi array");

System.out.println("input panjang array : ");

int size = in.nextInt();

int[] list = new int[size];

System.out.println("\nEnter "+ size +" integer elements");

for (int i = 0; i < size; i++)

list[i] = in.nextInt();

insertion_sort(list, size);

private static void insertion_sort(int arr[], int size){

int a,b;

System.out.println("\nProses Insertion Sort");

for (a = 0; a < arr.length; a++){

System.out.println("iterasi ke "+(a+1));

for(b = a+1; b >0 && b < arr.length; b--){

if(arr[b] < arr[b-1]){


// Proses Pertukaran

int temp = arr[b];

arr[b] = arr[b-1];

arr[b-1]= temp;

for (int y = 0; y < arr.length; y++) {

System.out.print(arr[y] + " ");

System.out.print("\n");

2. Bubble Sort

package Bubble_sort;

import java.util.Scanner;

public class Bubble_sort {

public static void main(String[] args) {

// TODO code application logic here

Scanner in = new Scanner(System.in);

System.out.println("Input panjang array : ");

int size = in.nextInt();

int[] list = new int[size];

System.out.println("\nInput "+ size +" elemen integer");

for (int i = 0; i < size; i++)


list[i] = in.nextInt();

bubble_sort(list, size);

private static void bubble_sort(int arr[], int size){

int counter, index;

for (counter = 0; counter < arr.length - 1; counter++){

for (index = 0; index < arr.length - 1 - counter; index++){

if (arr[index] > arr[index + 1]){

int temp = arr[index];

arr[index] = arr[index + 1];

arr[index + 1] = temp;

System.out.println("\niterasi ke : " + (counter+1)) ;

for(int x = 0; x < size; x++){

System.out.print(arr[x] + " ");

System.out.print("\n");

3. Selection Sort

package selection.sort;

import java.util.Scanner;

public class SelectionSort {


public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Input panjang array : ");

int size = in.nextInt();

int[] list = new int[size];

System.out.println("\nInput "+ size +" elemen integer");

for (int i = 0; i < size; i++)

list[i] = in.nextInt();

selection_sort(list, size);

private static void selection_sort(int arr[], int size){

for(int x=0; x<size;x++)

System.out.println("iterasi ke "+(x+1)+":");

boolean tukar= false;

int index=0;

int min = arr[x];

for(int y = x+1;y<size;y++){

if (min>arr[y])

tukar =true;

index =y;

min = arr[y];

}
}

if(tukar==true)

//perukaran data

int temp = arr[x];

arr[x]=arr[index];

arr[index]= temp;

for(int y=0;y<size;y++)

System.out.print(arr[y]+" ");

System.out.println("");

}
BAB III

RUNNING PROGRAM

1. Insertion Sort
2. Bubble Sort

3. Selection Sort

Vous aimerez peut-être aussi