Custom Search

Saturday 16 June 2012

Bubble Sort Using Java


import java.io.*;
public class bubblesort
{
public static void main(String ar[])throws IOException
{
int a[]=new int[10];
int n,i,t,j;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("enter the limit: ");
n=Integer.parseInt(br.readLine());
System.out.print("enter the elements: ");
for(i=0;i
{
a[i]=Integer.parseInt(br.readLine());
}
System.out.print("sorted array is\n");
for(i=0;i
{
for(j=1;j
{
if(a[j-1]>a[j])
{
t=a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
for(i=0;i
{
System.out.print(a[i]);
System.out.print("\t");
}
}
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...