Skip to content

Commit

Permalink
day 31 (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Feb 7, 2019
1 parent fab5ff7 commit 111c595
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions day31/Java/bubbleSort.java
@@ -0,0 +1,39 @@
/*
* 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 31/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class bubbleSort {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n,i,j;int t;
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter array");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
System.out.println("Sorted array is :");
for(i=0;i<n;i++)
System.out.print(arr[i]+" ");
}
}
39 changes: 39 additions & 0 deletions day31/README.md
Expand Up @@ -27,6 +27,45 @@ output: [1, 2, 3, 4, 5, 8, 9]
to be added
```

## Java Implementation

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

```java
/**
* @date 31/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class bubbleSort {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n,i,j;int t;
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter array");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
System.out.println("Sorted array is :");
for(i=0;i<n;i++)
System.out.print(arr[i]+" ");
}
}
```

### [C++ Implementation](./C++/bubbleSort.cpp)

```cpp
Expand Down

0 comments on commit 111c595

Please sign in to comment.