Created
October 4, 2016 13:35
-
-
Save YaoC/9fbafd1b3ccc1c93802fad5b09a65dc7 to your computer and use it in GitHub Desktop.
利用stack.h反转字符串
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "stack.h" | |
using namespace std; | |
int main() { | |
Stack strStack; | |
cout<<"Input s string: "; | |
string str; | |
getline(cin,str); | |
for(auto c:str)//C++ 11 这么写老师会觉得你比较厉害:) | |
strStack.push(c); | |
/*或者写成 | |
for(int i=0;i<str.size();i++) | |
strStack.push(str[i]) | |
*/ | |
cout<<"The reverse of string is "; | |
while (!strStack.isEmpty()) | |
cout<<strStack.pop(); | |
cout<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment