Vorzugsweise mit jedem Nicht-Virus Open-Source-LizenzJede fertige Implementierung von Radix Sort for C#?
Antwort
hier ist ein von wikibooks (Dies ist Least Significant Digit basiert)
public void RadixSort(int[] a)
{
// our helper array
int[] t=new int[a.Length];
// number of bits our group will be long
int r=4; // try to set this also to 2, 8 or 16 to see if it is
// quicker or not
// number of bits of a C# int
int b=32;
// counting and prefix arrays
// (note dimensions 2^r which is the number of all possible values of a
// r-bit number)
int[] count=new int[1<<r];
int[] pref=new int[1<<r];
// number of groups
int groups=(int)Math.Ceiling((double)b/(double)r);
// the mask to identify groups
int mask = (1<<r)-1;
// the algorithm:
for (int c=0, shift=0; c<groups; c++, shift+=r)
{
// reset count array
for (int j=0; j<count.Length; j++)
count[j]=0;
// counting elements of the c-th group
for (int i=0; i<a.Length; i++)
count[(a[i]>>shift)&mask]++;
// calculating prefixes
pref[0]=0;
for (int i=1; i<count.Length; i++)
pref[i]=pref[i-1]+count[i-1];
// from a[] to t[] elements ordered by c-th group
for (int i=0; i<a.Length; i++)
t[pref[(a[i]>>shift)&mask]++]=a[i];
// a[]=t[] and start again until the last group
t.CopyTo(a,0);
}
// a is sorted
}
Oh, 'count [(a [i] >> shift) & Maske] ++;' is so fk 'lesbar! – abatishchev
@abatishchev bitte mit besser lesbarer Version bearbeiten. – TheVillageIdiot
Es war kein Kommentar zu deiner Antwort, sondern zu diesem Wiki-Artikel. Ein Buch zum Erlernen von Algorithmen enthält kaum lesbaren und verständlichen Code. Sag nur) – abatishchev
public static int[] radixSort(int[] ar)
{
int width = 0;
foreach (int el in ar)
{
int numDigits = el.ToString().Length;
if (numDigits > width)
width = numDigits;
}
int md, n;
Dictionary<int, LinkedList> queue = null;
Action refreshQueue =() =>
{
queue = new Dictionary<int, LinkedList>();
for (int i = 0; i <= 9; i++)
{
queue[i] = null;
}
};
refreshQueue();
for (int i = 1; i <= width; i++)
{
md = (int)Math.Pow(10, i);
n = md/10;
foreach (int el in ar)
{
int ithPlace = (int)((el % md)/n);
if (queue[ithPlace] == null)
queue[ithPlace] = new LinkedList(new LinkedListNode(el));
else
queue[ithPlace].add(new LinkedListNode(el));
}
List<int> newArray = new List<int>();
for (int k = 0; k <= 9; k++)
{
if (queue[k] != null)
{
LinkedListNode head = queue[k].head;
while (head != null)
{
newArray.Add(head.value);
head = head.next;
}
}
}
ar = newArray.ToArray();
refreshQueue();
}
return ar;
}
- 1. Radix Sort implementiert in C++
- 2. Erklären Radix Sort
- 3. radix sort basis zustand?
- 4. Radix Sort Floating Data
- 5. Radix Sort, der Wert von r
- 6. Radix Sort, Sortieren von Float-Daten
- 7. Open-Source-Radix/mtrie Implementierung in C?
- 8. mit radix-sort auf reellen Zahlen
- 9. Java Natural Merge Sort Implementierung
- 10. Digitale Sum- und Sort-Implementierung
- 11. Javascript Radix Sortieren
- 12. ist diese Implementierung von merge sort gut?
- 13. Ist meine Bubble-Sort-Implementierung korrekt?
- 14. Radix Sortieralgorithmus Schwierigkeiten
- 15. Ist dies eine korrekte Implementierung von Insertion Sort?
- 16. Fertige Animationsbibliotheken
- 17. C# rechteckige Anordnung sort
- 18. Jede gute Implementierung von Fogbugz-Tastaturkürzeln?
- 19. Parsing Gleitkommazahl von Radix Nummer
- 20. C# Linq Custom Sort
- 21. LuceneNet - Jede Hadoop/HDFSDirectory-Implementierung?
- 22. C++: Eigene Bibliothek Neuling Sort
- 23. objective-c: sort NSMutableArray von OBJECT_IN_ARRAY.NSNUMBER!
- 24. Golang: Benchmark Radix Tree Lookup
- 25. Warum std nicht :: sort mein Operator <Implementierung
- 26. C++ - Probleme Quicksort Implementierung
- 27. Kann jede Iteration einer for-Schleife/for-each parallel erfolgen? (C++ 11)
- 28. C# Sort JSON-String Schlüssel
- 29. Gibt es eine gute radixsort-Implementierung für Floats in C#
- 30. C# IStream Implementierung von IStream
Was Sie unter "Nicht-Virus Open-Source-Lizenz" bedeuten kann ? – abatishchev