Menu
Abstract - The role of algorithms in software or programming is so important, so it is necessary to understand the basic concept of the algorithm. So a lot of logic programming that has been created, to the general case and also special. Pada contoh sebelumnya Anda telah belajar membuat program yang digunakan untuk mencari nilai maksimal dan/atau minimal dari sebuah array. Sekarang kita akan menginjak ke sesuatu yang sedikit lebih kompleks, yaitu mengurutkan array. Ada banyak metoda pengurutan array, namun setidaknya ada dua metoda yang cukup populer, yaitu Bubble Sort dan Quick Sort.
- Related Questions & Answers
- Selected Reading
Bubble sort is a simple sorting algorithm. This sorting algorithm is a comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order.
Let’s say our int has 5 elements:
Now, let us perform Bubble Sort.
Start with the first two elements 78 and 55. 55 is smaller than 78, so swap both of them. Now the list is:
Now 45 is less than 78, so swap it.
Now 98 is greater than 78, so keep as it is.
3 is less than 98, so swap it. Now the list looks like:
This was the first iteration. After performing all the iterations, e will get our sorted array using Bubble Sort:
Let us see an example with 10 elements in an array and sort it.