« Home | Program for print Ramanjan Numbers » | Overriding in java » | What is overloading in java » | Program to reverse a string » | XML Parser in Java » | Algorithms Used in Garbage collection » | Lower Case to Uppre Case Conversion » | PRINTING THE NON-PRIMES » | PRIME FACTORS OF ALL NON-PRIMES BELOW 500 » | What is Garbage Collection & Why is Garbage Collec... » 

Monday, April 10, 2006 

Bubble Sort

/** This is a program to implement bubble sort
Author : V.S.Phanindra
*/

The bubble sort is the oldest and simplest sort in use. Unfortunately, it's also the slowest, it sort works by comparing each item in the list with the item next to it, and swapping them if required.

Pros: Simplicity and ease of implementation.
Cons: Horribly inefficient.

class BubbleSort
{
public static void main(String[] args)
{
int a[]={2,1,4,6,8,9,-1,4,3,2};
int temp;

System.out.println("This is the List of elements before Sorting:");
for(int k=0;k<a.length;k++)
System.out.println(a[k]);
for(int i=0;i<a.length;i++)
{
for(int j=i+1;j<a.length-1;j++)
{
if (a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
} }
System.out.println("This is the sorted List of Elements:");
for(int j=0;j<a.length;j++)
System.out.println(a[j]);
}

}

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com