【发布时间】:2016-04-23 01:22:44
【问题描述】:
我正在使用堆栈和队列来完成整个回文程序。我们的教授让我们从头开始编写堆栈和队列,并且只针对字符串。我正在从文件中读取文本并确定该句子是否是回文。我显然需要将每个字符推入堆栈和队列,但是,我怎样才能将一个字符推入接受字符串作为参数的堆栈!?
//get data from txt file
void getData(Stack &myStack, Queue &myQueue)
{
ifstream infile;
string temp;
int i = 0;
infile.open("palindrome.txt");
if (!infile)
{
cout << "The file failed to open." << endl;
exit(-1);
}
while (getline(infile, temp))
{
//remove spaces form sentences
temp.erase(remove_if(temp.begin(), temp.end(), ::isspace),temp.end());
//need to push each character into stack and queue here
//there are 5 sentences total in the file to check
i++;
}
【问题讨论】:
标签: c++ palindrome