sorting - In-place radix sort in D programming language -


i'm trying in-place radix sort example in-place radix sort working. far have this:

import std.random;  void swap(ref string i,ref string j) {    string tmp = i;   = j;   j = tmp; }  void radixsort(ref string[] seqs, size_t base = 0) {     if(seqs.length == 0)         return;      size_t tpos = seqs.length, apos = 0;     size_t = 0;     while(i < tpos) {         if(seqs[i][base] == 'a') {              swap(seqs[i], seqs[apos++]);              i++;         }         else if(seqs[i][base] == 't') {             swap(seqs[i], seqs[--tpos]);         } else i++;     }      = apos;     size_t cpos = apos;     while(i < tpos) {         if(seqs[i][base] == 'c') {             swap(seqs[i], seqs[cpos++]);         }         i++;     }     if(base < seqs[0].length - 1) {         radixsort(seqs[0..apos], base + 1);         radixsort(seqs[apos..cpos], base + 1);         radixsort(seqs[cpos..tpos], base + 1);         radixsort(seqs[tpos..seqs.length], base + 1);    } }  void main(string[] args) {    string [] sequences;    for(int n=0;n<10;n++) {     string seq;     for(int i=0;i<10;i++) {       int r = rand()%4;       if(r == 0) seq = seq ~ "a";       if(r == 1) seq = seq ~ "c";       if(r == 2) seq = seq ~ "g";       if(r == 3) seq = seq ~ "t";     }     sequences = sequences ~ seq;   }    writefln("unsorted");   for(size_t n=0;n<10;n++) {     writefln(sequences[n]);   }    radixsort(sequences,0);    writefln("sorted");   for(size_t n=0;n<10;n++) {     writefln(sequences[n]);   } } 

however, fails with:

radix.d(36): error: slice expression seqs[0u..apos] not modifiable lvalue radix.d(37): error: slice expression seqs[apos..cpos] not modifiable lvalue radix.d(38): error: slice expression seqs[cpos..tpos] not modifiable lvalue radix.d(39): error: slice expression seqs[tpos..seqs.length] not modifiable lvalue 

under digital mars d compiler v1.066. guess slices not mutable, but... how should go fixing this?

i'm new d , largely interested in getting example working.

you need ref if want modify reference itself. array, means changing length or reallocating. since radix sort in-place, i'm not sure why you'd want that.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -