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";
    }
}
