Total Pageviews

BUBLE SORT

PROGRAM OF BUBLE SORT

import java.util.*;
class bst
{
public static void main(String[] args)
{
int i;
int array[] =new int();
System.out.print("Enter the length of list");
System.out.println("ENTER A LIST FOR SORTING");
Scanner sc=new Scanner(System.in);
for(i=0;i<array.length;i++)
{
array[i]=sc.nextInt();
}
System.out.println("Values Before the sort:");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+"  ");
System.out.println("\n");
bubble_srt(array, array.length);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+"  ");
}
public static void bubble_srt( int a[], int n )
{
int i, j,t=0;
for(i = 0; i < n; i++)
{
for(j = 1; j < (n-i); j++)
{
if(a[j-1] > a[j])
{
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
}
}


 

SEND FREE SMS ALL OVER WORLD AND EARN MONEY FOR YOUR MOBILE RECHARGE CLICK HERE...

IF YOU WANT EARN Rs.9,000PM WITHOUT ANY WORK  ....CLICK HERE

No comments:

Post a Comment