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