TL;DR

  • El Problema: Mecánica técnica del problema CTCI 12.2.
  • El Enfoque: CTCI problem 12.2 in C++: reverse a null-terminated C-style string in-place using pointer arithmetic.
  • Complejidad: Relación óptima de tiempo y memoria.

Este artículo explica claramente el problema CTCI 12.2.

1. Contexto y Enunciado

CTCI problem 12.2 in C++: reverse a null-terminated C-style string in-place using pointer arithmetic.

2. Código e Implementación

void reverse(char* str) {
    char* end = str;
    char tmp;
    if (str) {
        while (*end) { ++end; }
        --end;
        while (str < end) {
            tmp = *str;
            *str++ = *end;
            *end-- = tmp;
        }
    }
}

3. Resumen y Casos Límite

Verifique siempre condiciones de borde y entradas nulas.