Searching and sorting have been popular operations in elementry data structures. Although now a days many advanced sorting techniques are used to sort a set of data, the basic sorting methods are still popular and are the used frequently. Here C code for bubble sort is given. The algorithm for bubble sort is quite simple. In each iteration the adjacent elements are compared and they are swapped if their order is not correct. The complexity of this algorithm comes out to be O(n²).
The C code is as follows :
#include "stdio.h"
#include "conio.h"
void main( )
{
int arr[5] = { 25, 17, 31, 13, 2 } ;
int i, j, temp ;
for ( i = 0 ; i <= 3 ; i++ )
{
for ( j = 0 ; j <= 3 - i ; j++ )
{
if ( arr[j] > arr[j + 1] )
{
temp = arr[j] ;
arr[j] = arr[j + 1] ;
arr[j + 1] = temp ;
}
}
}
printf ( "\n\nArray after sorting:\n") ;
for ( i = 0 ; i <= 4 ; i++ )
printf ( "%d\t", arr[i] ) ;
}

Posted in
Tags: 

Hey. Nice code. Maybe you could have mentioned why it’s so famous and tell something about performance stuff.
it’s very easy to learn!!!!!!!!!!!!!!11