Custom Search

Saturday 16 June 2012

Insertion Sort Using JAVA


import java.io.*;
public class insertionsort
{
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.println("enter the limit: ");
n=Integer.parseInt(br.readLine());
System.out.println("enter the elements: ");
for(i=0;i
{
a[i]=Integer.parseInt(br.readLine());
}
System.out.print("sorted array is:\n");
for(i=1;i
{
t=a[i];
for(j=i-1;j>=0;j--)
{
if(t>a[j])
{
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...