Princeton1/clients/src/main/java/com/hithomelabs/clients/Benchmarks/Sortables/PartiallySortedApples.java
hitanshu310 743f6a761e
All checks were successful
sample gradle build and test / build (pull_request) Successful in 1m5s
Benchmarks complete
2025-02-17 22:38:53 +00:00

35 lines
979 B
Java

package com.hithomelabs.clients.Benchmarks.Sortables;
import com.hithomelabs.clients.Benchmarks.Sortable;
import com.hithomelabs.princeton1.common.Apple;
import com.hithomelabs.princeton1.module5.ComparableHelper;
import com.hithomelabs.princeton1.module8.HeapSort;
import java.util.Random;
public class PartiallySortedApples implements Sortable<Apple>, ComparableHelper {
Apple[] apples;
Random random;
public PartiallySortedApples(int size, int sizeRange){
random = new Random();
apples = new Apple[size];
for (int i = 0; i < size; i++)
apples[i] = new Apple(random.nextInt(sizeRange));
HeapSort.heapify(apples);
int N = apples.length;
for (int i = 0; i < N/2; i++)
ComparableHelper.exch(apples, i, N-i-1);
}
@Override
public Apple[] getArray() {
return apples.clone();
}
@Override
public String getOrdering() {
return "PARTIALLY SORTED";
}
}