Microsoft

  www.microsoft.com
Work in HR? Unlock Free Profile

Microsoft Software Engineer Interview Question (student candidate)

I interviewed in Seattle, WA and was asked:
"reverse an array in place"
Add Tags [?]
Answer

Part of a Software Engineer Interview Review - one of 3,411 Microsoft Interview Reviews

Answers & Comments

1
of 1
vote

be careful with the index of the array

- Interview Candidate on Nov 4, 2010
0
of 0
votes

//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

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.