双向队列
翻转单词顺序列
http://www.nowcoder.com/questionTerminal/3194a4f4cf814f63919d0790578d51f3
声明一个双向队列,先入后出即可满足要求
class Solution { public: string ReverseSentence(string str) { string tmp=""; deque<string> de; for(auto strnum:str) { if(strnum==' ') { de.push_back(tmp); tmp=""; } else { tmp=tmp+strnum; } } de.push_back(tmp); string result=de.back(); de.pop_back(); while(!de.empty()) { result=result+" "+de.back(); de.pop_back(); } return result; } };
