Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 27d7926

Browse filesBrowse files
Recursion Day 6 is completed
1 parent 095a677 commit 27d7926
Copy full SHA for 27d7926

File tree

2 files changed

+50
-0
lines changed
Filter options

2 files changed

+50
-0
lines changed

‎Recursion/BubbleSort.java

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package Recursion;
2+
3+
import java.util.Arrays;
4+
5+
public class BubbleSort {
6+
static void sort(int arr[],int row,int col) {
7+
if(row == 0)
8+
return;
9+
if(row>col) {
10+
if(arr[col]>arr[col+1]) {
11+
int temp = arr[col];
12+
arr[col] = arr[col+1];
13+
arr[col+1] = temp;
14+
}
15+
sort(arr, row, col+1);
16+
} else
17+
sort(arr, row-1, 0);
18+
}
19+
public static void main(String[] args) {
20+
int arr[] = {4, 1, 3, 9, 7 },row = arr.length-1,col=0;
21+
sort(arr,row,col);
22+
System.out.println(Arrays.toString(arr));
23+
}
24+
}

‎Recursion/SelectionSort.java

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Recursion;
2+
3+
import java.util.Arrays;
4+
5+
public class SelectionSort {
6+
static void sort(int arr[],int row,int col,int max) {
7+
if(row == 0)
8+
return;
9+
if(row>col) {
10+
if(arr[col]>arr[max]) {
11+
max = col;
12+
}
13+
sort(arr, row, col+1,max);
14+
} else{
15+
int temp = arr[col-1];
16+
arr[col-1] = arr[max];
17+
arr[max] = temp;
18+
sort(arr, row-1, 0,0);
19+
}
20+
}
21+
public static void main(String[] args) {
22+
int arr[] = {4, 1, 3, 9, 7 },row = arr.length-1,col=0,max = 0;
23+
sort(arr,row,col,max);
24+
System.out.println(Arrays.toString(arr));
25+
}
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.