Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

January 2, 2010

Insertion Sort

public static int[] insertionSort(int[] arr){
int len = arr.length;
for(int i = 0 ; i < len ; i++){
for(int j = 0 ; j < i ; j++){
if(arr[i] < arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;

}
}
}

return arr;
}

No comments: