-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
38 lines (29 loc) · 966 Bytes
/
BubbleSort.java
File metadata and controls
38 lines (29 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package June23;
import java.util.Scanner;
public class BubbleSort {
public static void bubblesort1(int arr[],int i,int j){
if(j==0)
return;
if(i<j){
if(arr[i]>arr[i+1]){
int temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
bubblesort1(arr,i+1,j);
}else{
bubblesort1(arr,0,j-1);
}
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<arr.length;i++)
arr[i]=sc.nextInt();
bubblesort1(arr,0,arr.length-1);
for(int i=0;i<arr.length;i++)
System.out.print(arr[i]+" ");
}
}