Want a Free Job Posting?

Buy a job posting today and the second one is on us. For a limited time only. Act Now.

Interview Question

Interview(Student Candidate) Seattle, WA

reverse an array in place


Interview Answer

2 Answers


be careful with the index of the array

Interview Candidate on Nov 4, 2010

//Reverse array in place template <class T> void reverse_in_place( T* src_array, size_t count) { if (src_array == NULL) return; if( count <= 1 ) return; //done typename T * front = &src_array[0]; typename T * back = &src_array[count-1]; while (front != back) { std::swap(*front, *back); front++; if(front == back) {break; } ; back--; } }

Keetah on Nov 13, 2010

Add Answers or Comments

To comment on this, Sign In or Sign Up.