-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aaff040
commit 6669ac6
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package javaapplication3; | ||
|
||
/** | ||
* @date 04/02/19 | ||
* @author SPREEHA DUTTA | ||
*/ | ||
import java.util.*; | ||
public class insertionSort { | ||
public static void sort(int arr[]) | ||
{ | ||
int i,j,t; | ||
for(i=0;i<arr.length;i++) | ||
{ | ||
t=arr[i]; | ||
j=i-1; | ||
while(j>=0 && arr[j]>t) | ||
{ | ||
arr[j+1]=arr[j]; | ||
j=j-1; | ||
} | ||
arr[j+1]=t; | ||
} | ||
System.out.println("Sorted array is "); | ||
for(i=0;i<arr.length;i++) | ||
System.out.print(arr[i]+" "); | ||
} | ||
public static void main(String []args) | ||
{ | ||
int a[]={4,2,7,5,1,6,8}; | ||
sort(a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters