Can some1 out there help me please!!
I need to modify the code i have for the s0orting module
I need code of how to count the no of comparisons nd to count the no of copies in the sorting.
Can some1 please help, ASAP!!!
public class Sorting {
public static void selectionSort (IComparable[] a, int left, int right,
bool tracing) {
// Sort a[left...right].
if (tracing) trace("\nInitially: ", a, left, right);
for (int l = left; l < right; l++) {
int p = l; IComparable least = a[p];
// ... least will always contain the value of a[p].
for (int k = l+1; k <= right; k++) {
int comp = a[k].CompareTo(least);
if (comp < 0) {
p = k; least = a[p];
}
}
if (p != l) {
a[p] = a[l]; a[l] = least;
}
if (tracing) trace("Iteration l = " + l + ":", a, left, right);
}
if (tracing) trace("Selection sort: ", a, left, right);
}
private static void trace (string caption, IComparable[] a,
int left, int right) {
Console.Write(caption + " {");
for (int k = left; k <= right; k++)
Console.Write(" " + a[k]);
Console.WriteLine(" }");
}
public static void Main (string[] args) {
string[] words1 = {"fox", "cow", "pig", "cat", "rat", "lio",
"tig", "goa", "dog"};
string[] words2;
int left = 0, right = words1.Length - 1;
words2 = (string[]) words1.Clone();
selectionSort(words2, left, right, true);
Need 2 put the code in above somewhere can spome1 help me??
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).