Insertion Sort-Java

package tests;

import org.testng.annotations.Test;

public class InsertionSortTest {

public void sort()
{
int []values={10,2,8,19,6};
insertionSort(values);
System.out.println(“———————-Insertion Sort——————————–“);
for(int i:values)
{
System.out.println(i);

}

}

public int [] insertionSort(int []values)
{
int temp;
for(int i=1;i<values.length;i++)
{
for(int j=i;j>0;j–)
{
if(values[j] < values[j-1])
{
temp=values[j];
values[j]=values[j-1];
values[j-1]=temp;

}//end of if
}//end of j
}//end of i

return values;
}
@Test
public void testInsertionSort() {

InsertionSortTest test=new InsertionSortTest();
test.sort();

}
}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized. Bookmark the permalink.

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