-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
49 lines (40 loc) · 1.3 KB
/
Main.java
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
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
public class Main {
public static void printOriginalArray(ArrayList<Student> students) {
System.out.println("Original array:");
for (Student student : students) {
System.out.print(student.getRollNo() + " ");
}
System.out.println();
}
public static void printSortedArray(ArrayList<Student> students) {
for (Student student : students) {
System.out.print(student.getRollNo() + " ");
}
System.out.println();
}
public static void compareStudents() {
Students studentsClass = new Students();
ArrayList<Student> students = studentsClass.students();
printOriginalArray(students);
Collections.sort(students, new RollNoComparator());
System.out.println("After Comparator sort:");
printSortedArray(students);
}
public static void doMergeSort() {
Students studentsClass = new Students();
ArrayList<Student> students = studentsClass.students();
MergeSort mergeClass = new MergeSort();
printOriginalArray(students);
mergeClass.mergeSort(students);
System.out.println("After merge sort:");
printSortedArray(students);
}
public static void main(String args[]) {
System.out.println("Using comparator class...");
compareStudents();
System.out.println("------------------------");
System.out.println("Using merge sort...");
doMergeSort();
}
}