"Beauty of Programming" 221 pages, question: string scr= "Aabcd", String des= "Cdaa", shift SRC, does it contain string des?
This book at the beginning of today, casually turned a few pages, not to mention the problem, the book is the layout of a lot of errors! Immediately feel that the book has lost the standard, it may be the printing problem it. For example, Char src[5]= "AABCD" ... such as
Record this small problem, because Lenovo to yesterday learned the direct insertion sort, is also in the array of adjacent 22 move between, by the way it included, so-called problem, as long as the same type, summed together!
The first thing to consider is the problem of displacement , there are two possible, either left or right, the book is to use the way of left shift.
After moving the AABCD, we get abcda, and the question is, where is the first move-on? According to the previous study, it is immediately possible to think of a temporary variable temporarily stored, wait until the shift, and then inserted into the appropriate position. There are many similarities to the code that is inserted directly into the sort.
Look at the outermost number of moves, AABCD, length 5, move 5 times,
String shift [Source: The beauty of programming]