我正在上课的分配。 我们提供了这 3 类 。 (链接在这里,编辑等得翻转时,我试图做他们在不同的行)。
我们应该采取一个字符串,然后使用这些类来测试它是否是一个回文。 我们不能修改说类。
这是我的int main
:
#include <iostream>
#include <cstring>
#include <cctype>
#include "stack.h"
using namespace std;
int main () {
char testString[100];
Stack<char> charStack;
cout << "Please enter a string:\n> ";
cin.getline(testString, 100);
char caps;
for (int i = 0; i < strlen(testString); i++) {
if (isalpha(testString[i])) {
caps = toupper(testString[i]);
charStack.push(caps);
}
}
for (int j = 0; j < strlen(testString); j++) {
if (isalpha(testString[j])) {
caps = toupper(testString[j]);
if (charStack.firstPtr->getData() == caps) { // This part is the issue. firstPtr is private in list.h, and I can't figure out another way to compare the char array to the data in the stack
charStack.pop(caps);
}
}
}
if (charStack.isStackEmpty()) {
cout << endl << endl << "\"" << testString << "\" IS a palindrome." << endl;
}
else {
cout << endl << endl << "\"" << testString << "\" is NOT a palindrome." << endl;
}
}
正如你所看到的,我不能完全弄清楚如何将字符数组,在弹出数据进行比较的数据。 Stack类只返回一个布尔值,以及指针ListNode对象类List是私有的,所以我不能使用该类的“的getData”功能! 任何人都可以帮助我任何提示?
谢谢!