It was suggested that Swift include a stable (or merge) sort function and I hope this becomes the case. At present, however, we must turn to pure Swift implementations presented by others or turn to the C functions accessible through Swift. (According to the man pages , mergesort: is a stable sort function.) It should be noted that the mergesort: function has some restrictions that make generic use difficult if not impossible. Not least connected to closures, but at the moment I just want to look at the basics of mergesort: public func mergesort(_ __base: UnsafeMutableRawPointer!, _ __nel: Int, _ __width: Int, _ __compar: @escaping @convention(c) (UnsafeRawPointer?, UnsafeRawPointer?) -> Int32) -> Int32 This is quite an unwieldy looking function but let's break it down. base: this is a pointer to a mutable array, which can be implemented using the in-out notation of & so &arrayName is what you'll see here nel: is the array length, so arrayName.co
Technology tips for writers, editors, designers, illustrators, programmers and publishers, and now Retro Gamers.