Skip to content

Instantly share code, notes, and snippets.

@YaoC
Created October 4, 2016 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YaoC/9fbafd1b3ccc1c93802fad5b09a65dc7 to your computer and use it in GitHub Desktop.
Save YaoC/9fbafd1b3ccc1c93802fad5b09a65dc7 to your computer and use it in GitHub Desktop.
利用stack.h反转字符串
#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