..
Sorting a list of objects is one of the fundamental problems of computing. There are several ways to do this and they fall in the so-called sorting algorithms. Some of these algorithms are simple and intuitive, while others are more complex and allow for better performance.
Among the best known and most popular sorting algorithms are:
The Bubble Sort works by comparing each element of a list with the next item, instead of exchanging them if necessary. The algorithm repeats this process until it runs the entire list without exchanges between elements. The name bubble (bubble) stems from the way in which elements are ordered: the smaller ones go back to their correct positions in the list, just like bubbles in a fizzy drink. Because of this way of doing this algorithm is considered the most inefficient among those listed.
Here's the code of an implementation of this algorithm:
/ / Array of integers
private int [] a = new int [100];
/ / Number of elements in the
private int x;
public void BubbleSort ()
{
int i;
int j;
int temp;
for (i = (x - 1); i> = 0; i -)
{
for (j = 1 j <= i, j + +)
{
if (a [j - 1]> a [j])
{
temp = a [j - 1];
a [j - 1] = a [j];
a [j] = temp;
}
}
}
}
| |
ASP Zero (Ebook)
Learning Microsoft ASP and VBScript from scratch. At only 29 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |
| |
Web Marketing (Course)
Site promotion, search engines and marketing. From 39 €. |