Math Namespace?
-
igor1960 wrote: Math Namespace? System.Math - it's a class, not a namespace. igor1960 wrote: "qsort" :confused:
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
quicksort for you, strait from Rotor.
private class SorterObjectArray
{
private Object[] keys;
private Object[] items;
private IComparer comparer;public SorterObjectArray(Object\[\] keys, Object\[\] items, IComparer comparer) { if (comparer == null) comparer = Comparer.Default; this.keys = keys; this.items = items; this.comparer = comparer; } public virtual void QuickSort(int left, int right) { // Can use the much faster jit helpers for array access. do { int i = left; int j = right; Object x = keys\[(i + j) >> 1\]; do { // Add a try block here to detect IComparers (or their // underlying IComparables, etc) that are bogus. try { while (comparer.Compare(keys\[i\], x) < 0) i++; while (comparer.Compare(x, keys\[j\]) < 0) j--; } catch (IndexOutOfRangeException) { throw new ArgumentException(String.Format(Environment.GetResourceString("Arg\_BogusIComparer"), x, x.GetType().Name, comparer)); } catch (Exception e) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation\_IComparerFailed"), e); } BCLDebug.Assert(i>=left && j<=right, "(i>=left && j<=right) Sort failed - Is your IComparer bogus?"); if (i > j) break; if (i < j) { Object key = keys\[i\]; keys\[i\] = keys\[j\]; keys\[j\] = key; if (items != null) { Object item = items\[i\]; items\[i\] = items\[j\]; items\[j\] = item; } } i++; j--; } while (i <= j); if (j - left <= right - i) { if (left < j) QuickSort(left, j); left = i; } else { if (i < right) QuickSort(i, right); right = j; } } while (left < right); }
}
-
quicksort for you, strait from Rotor.
private class SorterObjectArray
{
private Object[] keys;
private Object[] items;
private IComparer comparer;public SorterObjectArray(Object\[\] keys, Object\[\] items, IComparer comparer) { if (comparer == null) comparer = Comparer.Default; this.keys = keys; this.items = items; this.comparer = comparer; } public virtual void QuickSort(int left, int right) { // Can use the much faster jit helpers for array access. do { int i = left; int j = right; Object x = keys\[(i + j) >> 1\]; do { // Add a try block here to detect IComparers (or their // underlying IComparables, etc) that are bogus. try { while (comparer.Compare(keys\[i\], x) < 0) i++; while (comparer.Compare(x, keys\[j\]) < 0) j--; } catch (IndexOutOfRangeException) { throw new ArgumentException(String.Format(Environment.GetResourceString("Arg\_BogusIComparer"), x, x.GetType().Name, comparer)); } catch (Exception e) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation\_IComparerFailed"), e); } BCLDebug.Assert(i>=left && j<=right, "(i>=left && j<=right) Sort failed - Is your IComparer bogus?"); if (i > j) break; if (i < j) { Object key = keys\[i\]; keys\[i\] = keys\[j\]; keys\[j\] = key; if (items != null) { Object item = items\[i\]; items\[i\] = items\[j\]; items\[j\] = item; } } i++; j--; } while (i <= j); if (j - left <= right - i) { if (left < j) QuickSort(left, j); left = i; } else { if (i < right) QuickSort(i, right); right = j; } } while (left < right); }
}
-
Any reason you can't use the Array.Sort static method? I think that is the method that leppie gave the code from. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
-
Any reason you can't use the Array.Sort static method? I think that is the method that leppie gave the code from. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
James T. Johnson wrote: I think that is the method that leppie gave the code from. Correct :) You are one of the few people that actually types "leppie" not "Leppie" :laugh: I wonder why some people capitalize the 'l'? leppie::AllocCPArticle(Generic DFA State Machine for .NET);
-
Any reason you can't use the Array.Sort static method? I think that is the method that leppie gave the code from. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
-
James T. Johnson wrote: I think that is the method that leppie gave the code from. Correct :) You are one of the few people that actually types "leppie" not "Leppie" :laugh: I wonder why some people capitalize the 'l'? leppie::AllocCPArticle(Generic DFA State Machine for .NET);
I'm sure they will spell it correctly on the plagarism award.
-
I'm sure they will spell it correctly on the plagarism award.
Maybe you need glasses, or didnt you notice the "From Rotor" part? Perhaps invest in a dictionary. leppie::AllocCPArticle(Generic DFA State Machine for .NET);
-
Maybe you need glasses, or didnt you notice the "From Rotor" part? Perhaps invest in a dictionary. leppie::AllocCPArticle(Generic DFA State Machine for .NET);
I do wear glasses thank you. Perhaps you could recommend an Optometrist or you could write a dictionary for me( a copy www.m-w.com would be fine) Please respond so it boosts your posted rate, after all quantity certainly beats quality. :rolleyes: Sorry I forgot about the clickety police www.m-w.com[^]