File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ This is a repository containing various Java Programs to understand the basic co
8
8
9
9
Java Codes for solving some of the Arrays related problems.
10
10
11
+ * [ Searching] ( https://github.com/muskanmi/Data-Structures-Java/tree/main/Searching ) :
12
+
13
+ Java Codes for various searching algorithms.
14
+
15
+ * [ Sorting] ( https://github.com/muskanmi/Data-Structures-Java/tree/main/Sorting ) :
16
+
17
+ Java Codes for various sorting algorithms.
18
+
11
19
* [ Recursion] ( https://github.com/muskanmi/Data-Structures-Java/tree/main/recursion ) :
12
20
13
21
Java Codes for solving some problems of recursion.
Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .Scanner ;
3
+
4
+ public class BubbleSort {
5
+ static void bubbleSort (int [] arr ) {
6
+ int n = arr .length ;
7
+ int t = 0 ;
8
+ for (int i =0 ; i <n ; i ++){
9
+ for (int j =1 ; j <(n -i ); j ++){
10
+ if (arr [j -1 ] > arr [j ]){
11
+ t = arr [j -1 ];
12
+ arr [j -1 ] = arr [j ];
13
+ arr [j ] = t ;
14
+ }
15
+ }
16
+ }
17
+ }
18
+
19
+ public static void main (String a []){
20
+ Scanner scanner = new Scanner (System .in );
21
+
22
+ System .out .print ("Enter the number of elements in the array: " );
23
+ int n = scanner .nextInt ();
24
+ int arr [] = new int [n ];
25
+
26
+ System .out .println ("Enter the elements of the array:" );
27
+ for (int i =0 ; i <n ; i ++) {
28
+ arr [i ] = scanner .nextInt ();
29
+ }
30
+
31
+ bubbleSort (arr );
32
+
33
+ System .out .println ("Sorted Array:" );
34
+ for (int i =0 ; i <n ; i ++) {
35
+ System .out .print (arr [i ]+ " " );
36
+ }
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments