Insertion Sort Example program in JAVA


package in.malliktalksjava;

/**
* @author malliktalksjava
* This class sort an array using Insertion sort algorithm.
*
*/
public class InsertionSortExample {

/**
* @param args
*/
public static void main(String args[]){
int[] arr1 = {10,34,2,56,7,67,88,42};
int[] arr2 = doInsertionSort(arr1);
for(int counts:arr2){
System.out.print(counts);
System.out.print(“, “);
}
}

/**
* @param input
* @return
*/
/**
* @param input
* @return
*/
public static int[] doInsertionSort(int[] input){

int temp;
for (int count = 1; count < input.length; count++) {
for(int count2 = count ; count2 > 0 ; count2–){
if(input[count2] < input[count2-1]){
temp = input[count2];
input[count2] = input[count2-1];
input[count2-1] = temp;
}
}
}
return input;
}
}

 

Other Useful Links:

Selection Sort Example Program in JAVA

Bubble Sort Example in JAVA

Quick Sort Example Program in Java

Merge Sort Example in Java

Advertisements
About

I born in Good cultural place called India. My family is traditional family. We fallow all Indian traditions.

Tagged with: , ,
Posted in JAVA
4 comments on “Insertion Sort Example program in JAVA
  1. […] Insertion Sort Example program in JAVA […]

  2. […] Insertion Sort Example program in JAVA […]

  3. […] Insertion Sort Example program in JAVA […]

  4. […] Insertion Sort Example program in JAVA […]

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 678 other followers

Calendar
April 2014
M T W T F S S
« Feb   May »
 123456
78910111213
14151617181920
21222324252627
282930  
Mallikarjun Gunda

This is Mallikarjun Gunda, I am working as a software professional. Blogging is my Passion. This blog contains the posts on Java related technologies and programming languages. I am happy to share my knowledge through the blogs.

Blog Stats
  • 281,110 hits
IndiBlogger
malliktalksjava.wordpress.c...
70/100