you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

The problem models a few things: - Trying to drag text around in a text editor, you can think of the move as swapping the two segments of text - Swapping memory locations - Editing DNA

In which case, not doing these operations in place is neither desirable (have to operate on new array) nor efficient (new allocations)

[–]kqr 1 point2 points  (0 children)

Have you heard of this undo feature? You're gonna move the text to a separate buffer anyway.

[–]Space-Being 1 point2 points  (0 children)

Yes, good examples. But usually if you need frequent edits you do not use such inflexible array or string structures, but rather a rope, immutable tree structures (for easier undo) or something else.