How should I sort a doubly linked list the D way?

Mirjam Akkersdijk noreply at
Tue Aug 13 14:29:35 UTC 2019

On Tuesday, 13 August 2019 at 12:34:46 UTC, bachmeier wrote:
> I'm confused by this statement. Are you referring to the qsort 
> in C's stdlib? I had never heard of using that to sort a linked 
> list, so I searched, and it is not possible.

Ah yes, maybe I should have elaborated. In C, you can just create 
an array

(1) struct Node* nodes[buf_size];

and then loop over it, filling it with

(2) nodes[i] = (DLLbuf + i * sizeof(struct Node));

subsequently calling our dear friend from stdlib

(3) qsort(nodes, buf_size, sizeof(struct Node*), 

You can then rechain all nodes together but that's a bit out of 
scope for this thread unless you do really want me to work it out 

But I was looking for a more D-specific approach to solve this, 
as it feels archaic to do it the C way. If there is anyone with a 
better one please let me know.

More information about the Digitalmars-d-learn mailing list