Skip to content

Commit

Permalink
day 33 (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Feb 7, 2019
1 parent aaff040 commit 6669ac6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
37 changes: 37 additions & 0 deletions day33/Java/insertionSort.java
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);
}
}
37 changes: 37 additions & 0 deletions day33/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,41 @@ function insertionSort(arr){
}

console.log ( insertionSort ([1, 5, 2, 7, 3, 4, 8, 9, 6]));
```

## Java Implementation

### [Solution](./Java/insertionSort.java)

```java
/**
* @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);
}
}
```

0 comments on commit 6669ac6

Please sign in to comment.