Skip to content

Commit 39e8f55

Browse files
Mohit KumarMohit Kumar
Mohit Kumar
authored and
Mohit Kumar
committedOct 19, 2018
feat: add algorithms in java
1 parent 0161400 commit 39e8f55

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
 

‎.DS_Store

8 KB
Binary file not shown.

‎Data Structures in JAVA/.DS_Store

8 KB
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import java.util.*;
2+
3+
public class Sorts {
4+
5+
public static Scanner sc = new Scanner(System.in);
6+
7+
public static void main(String[] args) {
8+
9+
// alterNateSort();
10+
// sortAbsoluteDiff();
11+
sort2DArrayByCol(new int[][]{{3,4,5,6},{1,2,3,4},{6,7,8,9},{9,0,1,2}},4);
12+
}
13+
14+
public static void alterNateSort() {
15+
int t = sc.nextInt();
16+
int[] arr = new int[t];
17+
18+
for (int i=0;i<t;i++) {
19+
arr[i] = sc.nextInt();
20+
}
21+
22+
Arrays.sort(arr);
23+
24+
int start = 0;
25+
int last = t-1;
26+
27+
while (start < last) {
28+
System.out.print(arr[start++] + " ");
29+
System.out.print(arr[last--] + " ");
30+
}
31+
}
32+
33+
public static void sortAbsoluteDiff() {
34+
int t = sc.nextInt();
35+
ArrayList<Integer> list = new ArrayList<Integer>();
36+
37+
for (int i=0;i<t;i++) {
38+
list.add(sc.nextInt());
39+
}
40+
41+
int x = sc.nextInt();
42+
43+
}
44+
45+
public static void sort2DArrayByCol(int[][] arr,int col) {
46+
47+
Arrays.sort(arr, new Comparator<int[]>() {
48+
@Override
49+
public int compare(int[] ar1,int[] ar2) {
50+
if (ar1[col-1] > ar2[col-1]) {
51+
return 1;
52+
} else {
53+
return -1;
54+
}
55+
}
56+
});
57+
58+
for (int i=0;i<arr.length;i++) {
59+
for (int j=0;j<arr[0].length;j++) {
60+
System.out.print(arr[i][j] + " ");
61+
}
62+
System.out.println();
63+
}
64+
65+
}
66+
67+
}

0 commit comments

Comments
 (0)
Please sign in to comment.