String shift [Source: The beauty of programming]

Source: Internet
Author: User

"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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.