Princeton1/module5/src/main/java/com/hithomelabs/princeton1/module5/ComparableHelper.java
hitanshu310 8c47ac248c Adding benchmarking code (#17)
Reviewed-on: Hithomelabs/Princeton1#17
Reviewed-by: kruti <krutis0201@gmail.com>
Co-authored-by: hitanshu310 <hitanshu98@gmail.com>
Co-committed-by: hitanshu310 <hitanshu98@gmail.com>
2025-02-19 19:53:59 +00:00

19 lines
492 B
Java

package com.hithomelabs.princeton1.module5;
// * * Provides a set of helper functions less and exch for Comparable data types
public interface ComparableHelper {
static <T> void exch(T[] arr, int j, int i) {
T temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static <T> boolean less(T e1, T e2) {
return ((Comparable<T>)e1).compareTo(e2) < 0;
}
static <T> boolean equals(T e1, T e2) { return ((Comparable<T>)e1).compareTo(e2) == 0;}
}