Sunday, August 18, 2013

Getting Started && reverse a C-Style String

During the preparation for technical interviews, I've reviewed some commonly used data structures and algorithms, and also wrote quite a few small programs. Sometimes I think and try to tackle by myself, sometimes discuss with my good friends. It feels good to be focused in studying and using those algorithms; many times we are just amazed by those smart ideas and approaches.

SF's cool and mild weather brings me soft breezes and good mood. So wonderful I have come here. Now it's time to keep down some problems I've solved, to (hopefully) share with others, and to improve day by day.

Most of the problems are from the book Cracking the Coding Interview, some are from various online resources.

Ok the first one. From Cracking the Coding Interview 1-2.

/* Write code to reverse a C-Style String.
 (C-String means that “abcd” is represented as five characters, including the null character.) */

void reverseCString(char * a) {
    size_t size = strlen(a);
    for (size_t i = 0; i < size/2; i++) {
        std::swap(a[i], a[size-1-i]);
    }

}

No comments:

Post a Comment