Using the Code

To use the algorithm, you must have an array to sort and an implementation of IComparer that will compare instances of the array type. The following code shows a simple example using an int array:

using System;

using System.Collections.Generic; namespace Parallel_Sort { class Use_Parallel_Sort {

static void Main(string[] args) {

// generate some random source data Random rnd = new Random(); int[] sourceData = new int[5000000]; for (int i = 0; i < sourceData.Length; i++) { sourceData[i] = rnd.Next(1, 100);

// perform the parallel sort

Parallel_Sort<int>.ParallelQuickSort(sourceData, new IntComparer());

public class IntComparer : IComparer<int> { public int Compare(int first, int second) { return first.CompareTo(second);

0 0

Post a comment