Bubble Sort

import java.io.*;
class BubbleSort
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);

String ARR[]=new String[10];

System.out.println(“Enter 10 numbers”);
int i,j;
String temp=””;

for(i=0;i<10;i++)
{
ARR[i]=y.readLine();
}

for(i=0;i<10;i++)
{
for(j=0;j<10-i-1;j++)
{
if(ARR[j].compareTo(ARR[j+1])>0)
{
temp=ARR[j];
ARR[j]=ARR[j+1];
ARR[j+1]=temp;
}
}
}

for(i=0;i<10;i++)
{
System.out.print(ARR[i]+” “);
}
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s