www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12563] New: std.container.SList.reverse

https://issues.dlang.org/show_bug.cgi?id=12563

          Issue ID: 12563
           Summary: std.container.SList.reverse
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

I suggest to add to std.container.SList a method that reverses the list
in-place efficiently (O(n) and with no or nearly no memory allocations),
equivalent to this functions that reverses a singly linked list:

Node* reverse(Node* s1) pure nothrow {
    Node* s2;
    while (s1) {
        auto next = s1.next;
        s1.next = s2;
        s2 = s1;
        s1 = next;
    }
    return s2;
}

--
Apr 11 2014