-- It is considered as Most In efficient Sorting Algorithm.
How it works?
The basic idea is to compare two neighboring objects, and to swap them if they are in the wrong order. This process is repeated until it completly sorts the list. This causes larger values to "bubble" to the end of the list while smaller values "sink" towards the begining of the list.
C# Code :
// integers array to hold values
private int[] a = new int[100];
// number of elements in array
private int x;
// Bubble Sort Algorithm
public void sortArray()
{
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 ;
}
}
}
}
3 comments:
GREAT post!!!
10x
Thanks to you too
thanks for sharing this site. you can download lots of ebook from here
http://feboook.blogspot.com
Post a Comment