Pocket Gems Interview Question

1. Write a method to reverse a string in place (constant space and linear time).

Interview Answers

Anonymous

Nov 10, 2013

void strrev(char *p) { char *q = p; while(q && *q) ++q; for(--q; p < q; ++p, --q) *p = *p ^ *q, *q = *p ^ *q, *p = *p ^ *q; }

Anonymous

Apr 24, 2013

fairly straightforward, except in most languages strings are immutable.