Simple Way to Learn Insertion Sort in JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Tuesday, June 30, 2020

Simple Way to Learn Insertion Sort in JAVA

Program of Insertion Sort in JAVA
public class InsertionSort {
    public static void main(String[] args) {
        int array[]={5,3,8,6,1,4,12,14,16,11,9,123,121,89};
        int temp,j;
        for (int i=1;i<array.length;i++){
            temp=array[i];
            j=i;
            while (j>0&&array[j-1]>temp){
                array[j]=array[j-1];
                j=j-1;
            }
            array[j]=temp;
        }
        for (int i=0;i<array.length;i++){
            System.out.print(array[i]+" ");
        }
    }
}
Output : 



 Click to next or Searching Programs
Start with your Choice
-Important Programs for Freshers
Learn Pattern Programs 
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

Learn with us | HTML | CSS | Java Script | Bootstrap | JAVA | ADV JAVA | SQL | GIT

No comments:

Pages