(61). 23.2 STACK CHALLENGE (REVERSE A SENTENCE) USING STACK - anishsingh90/Data_Structure_And_Algorithm_In_Cpp_github.io GitHub Wiki
#include<bits/stdc++.h> using namespace std;
//reverse function void reverseSentence(string s){ stack st;
for(int i=0; i<s.length(); i++){
string word = "";
while(s[i] != ' ' && i<s.length()){
word += s[i];
i++;
}
st.push(word);
}
while(!st.empty()){
cout << st.top() << " ";
st.pop();
}
cout << endl;
}
int main(){ string s = "Hey, how are you doing?"; reverseSentence(s);
return 0; }
/* OUTPUT: doing? you are how Hey, */