|
-
Mar 5th, 2011, 06:23 PM
#1
Thread Starter
Addicted Member
C# sort implementation that's as fast or faster than Array.Sort?
Array.Sort is supposedly QuickSort (I think that's what it says on MSDN).
But using a QuickSort algorithm written in C# and comparing it to the built-in sort function Array.Sort, the QuickSort implementation was maybe about 2.5 or more times slower?
Is there a sorting algorithm that will work as fast as the built in algorithm?
And, what I want to do is sort an array of indices
E.g. I have an array of elements, 100 elements, so MyArray[100] (0-99) of elements to be sorted.
And an array of indices MyIndices[100] of indices from 0-99.
So
MyArray [0....1...2..] = Item1, Item2, Item3....
MyIndices[0..1..2..3..]= 0...1...2..3...
Instead of sorting (swapping) the elements in MyArray
I want to only swap the Indices, and the algorithm compares the elements in MyArray.
Is there a way to use Array.Sort or something to do this without making a copy of an array? I think Array.Sort can do it but it just swaps both instead of swapping only the indices, so to keep MyArray intact, you feed it a copy of it.. Array.CopyTo() or something..
I have written a Index Quicksort, but it is about 2-2.5x slower than Array.Sort.
So I want to either be able to do it with the faster built in sort or have a C# implementation that's as fast or faster.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|