Skip to content

Commit 111c595

Browse files
SpreehaMadhavBahl
authored andcommitted
day 31 (#217)
1 parent fab5ff7 commit 111c595

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

day31/Java/bubbleSort.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package javaapplication3;
7+
8+
/**
9+
* @date 31/01/19
10+
* @author SPREEHA DUTTA
11+
*/
12+
import java.util.*;
13+
public class bubbleSort {
14+
public static void main(String []args)
15+
{
16+
Scanner sc=new Scanner(System.in);
17+
int n,i,j;int t;
18+
n=sc.nextInt();
19+
int arr[]=new int[n];
20+
System.out.println("Enter array");
21+
for(i=0;i<n;i++)
22+
arr[i]=sc.nextInt();
23+
for(i=0;i<n-1;i++)
24+
{
25+
for(j=0;j<n-1-i;j++)
26+
{
27+
if(arr[j]>arr[j+1])
28+
{
29+
t=arr[j];
30+
arr[j]=arr[j+1];
31+
arr[j+1]=t;
32+
}
33+
}
34+
}
35+
System.out.println("Sorted array is :");
36+
for(i=0;i<n;i++)
37+
System.out.print(arr[i]+" ");
38+
}
39+
}

day31/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,45 @@ output: [1, 2, 3, 4, 5, 8, 9]
2727
to be added
2828
```
2929

30+
## Java Implementation
31+
32+
### [Solution](./Java/bubbleSort.java)
33+
34+
```java
35+
/**
36+
* @date 31/01/19
37+
* @author SPREEHA DUTTA
38+
*/
39+
import java.util.*;
40+
public class bubbleSort {
41+
public static void main(String []args)
42+
{
43+
Scanner sc=new Scanner(System.in);
44+
int n,i,j;int t;
45+
n=sc.nextInt();
46+
int arr[]=new int[n];
47+
System.out.println("Enter array");
48+
for(i=0;i<n;i++)
49+
arr[i]=sc.nextInt();
50+
for(i=0;i<n-1;i++)
51+
{
52+
for(j=0;j<n-1-i;j++)
53+
{
54+
if(arr[j]>arr[j+1])
55+
{
56+
t=arr[j];
57+
arr[j]=arr[j+1];
58+
arr[j+1]=t;
59+
}
60+
}
61+
}
62+
System.out.println("Sorted array is :");
63+
for(i=0;i<n;i++)
64+
System.out.print(arr[i]+" ");
65+
}
66+
}
67+
```
68+
3069
### [C++ Implementation](./C++/bubbleSort.cpp)
3170

3271
```cpp

0 commit comments

Comments
 (0)