the following is my insertion sort code. remember it: /* (c) Copyright 2018, 2019…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
the following is my insertion sort code. remember it:
/* (c) Copyright 2018, 2019 Phasmid Software */ package edu.neu.coe.info6205.sort.elementary;
import edu.neu.coe.info6205.sort.BaseHelper; import edu.neu.coe.info6205.sort.Helper; import edu.neu.coe.info6205.sort.SortWithHelper; import edu.neu.coe.info6205.util.Config;
public class InsertionSort<X extends Comparable> extends SortWithHelper {
code/** * Constructor for any sub-classes to use. * * @param description the description. * @param N the number of elements expected. * @param config the configuration. */ protected InsertionSort(String description, int N, Config config) { super(description, N, config); } /** * Constructor for InsertionSort * * @param N the number elements we expect to sort. * @param config the configuration. */ public InsertionSort(int N, Config config) { this(DESCRIPTION, N, config); } public InsertionSort(Config config) { this(new BaseHelper<>(DESCRIPTION, config)); } /** * Constructor for InsertionSort * * @param helper an explicit instance of Helper to be used. */ public InsertionSort(Helper<X> helper) { super(helper); } public InsertionSort() { this(BaseHelper.getHelper(InsertionSort.class)); } /** * Sort the sub-array xs:from:to using insertion sort. * * @param xs sort the array xs from "from" to "to". * @param from the index of the first element to sort * @param to the index of the first element not to sort */ public void sort(X[] xs, int from, int to) { final Helper<X> helper = getHelper(); for (int outer = from + 1; outer < to; outer++) { int inner = outer; while (inner > from) { if (helper.compare(xs[inner], xs[inner - 1]) < 0) { helper.swap(xs, inner - 1, inner); } else { break; } inner--; } } } public static final String DESCRIPTION = "Insertion sort"; public static <T extends Comparable<T>> void sort(T[] ts) { new InsertionSort<T>().mutatingSort(ts); } - Assistant
I have saved your InsertionSort code in a variable. If you need me to recall it, just let me know!
Here's the InsertionSort code for reference:
java
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.