It seems very inefficient, though
that was not difficult
I am not very happy about this solution; it is really crap
perhaps one could use sort right away; Also I think the insert can be simplified a bit…
Why is there an extra char at the beginning of the buffer?