Microsoft Interview Question

design an elevator(uml+implementation+threads& syncroniczation and locking)

Interview Answers

Anonymous

Jan 26, 2013

apparently according to the interviewer the data structure you should use is a binary tree for moving the elevator

Anonymous

Feb 6, 2013

void reverseWord(string& word) { int size = word.size(); int mid = size/2; char temp; for (int i = 0; i < mid; ++i) { temp = word[i]; word[i] = word[size-i-1]; word[size-i-1] = temp; } } void reverseSentence(string& sent) { // 1. reverse the sentence reverseWord(sent); // 2. reverse each individual word in the sentence int i(0); while (i < sent.size()) { // assume words are separated by spaces, no punctuation int j = i; while (j < sent.size() && sent[j] != ' ') ++j; // reverse current word and replace it in the sentence string word = sent.substr(i, j-i); reverseWord(word); sent.replace(i, j-i, word); // advance i i += j+1; } }