-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting_JavaGeneric.java
More file actions
35 lines (23 loc) · 871 Bytes
/
Sorting_JavaGeneric.java
File metadata and controls
35 lines (23 loc) · 871 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
public class Two {
public static <T extends Comparable <T>> void workWithElement(T arr[]){
for(int i = 0; i < arr.length -1; i++){
for(int j = 0; j < arr.length -i - 1; j++){
if(arr[j].compareTo(arr[j+1]) > 0){
T temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
}
public static void main(String args[]) {
Integer arr[] = {3, 1, 5, 4, 2};
workWithElement(arr);
System.out.println("");
String names[] = {"Rakib", "Ajmira", "Sathi", "Yamin"};
workWithElement(names);
}
}