C++ 字符串对称性判断:使用栈数据结构
#include
#define N 20
bool symmetry(string str) { int i; char e; sqstack *st; string prompt1 = 'please input string for judge'; cout << prompt1 << endl; getline(cin, str); initstack(st); for (i = 0; i < str.length(); i++) pushstack(st, str[i]); for (i = 0; i < str.length(); i++) { popstack(st, e); if (str[i] != e) { destroystack(st); cout << 'is not sym' << endl; return false; } } destroystack(st); cout << 'is sym' << endl; return true; }
原文地址: https://www.cveoy.top/t/topic/pKh5 著作权归作者所有。请勿转载和采集!