Hi,
I'm new here.. sorry if this question is funny.i Got this question and answer online..i just want to study it..but when i'm try to compile it, the code got some errors...can anyone help?
Consider the problem of recognizing whether a particular string is in the language:
L = { w$w’: w is a possibly empty string of characters other than $, w’ = reverse(w) }.
Write a C program to determining whether a given string is in L. You must apply stacks to solve this question.
Output Sample 1:
Input a string: ABC$CBA
Result: The above string is in the language
Output Sample 2:
Input a string: ABCD$CB
Result: The above string is not in the language
Code:#include <iostream> #include <string> #include <stack> using namespace std; typedef char StackItemType; class Stack { private: stack<StackItemType> s; public: bool isEmpty() const { return s.empty(); } void push(const StackItemType & v) { s.push(v); } void pop() { s.pop(); } void pop(StackItemType & stackTop) { stackTop = s.top(); s.pop(); } void getTop(StackItemType & stackTop) { stackTop = s.top(); } int size() { return s.size(); } }; // TODO(student9#9#): Write your code here // Begin Question bool isInTheLanguage(const string & input) { } // End Question int main(int argc, char* argv[]) { string input; bool inLanguage = false; cout << "Input a string: "; cin >> input; inLanguage = isInTheLanguage(input); if (inLanguage) { cout << "Result: The above string is in the language" << endl; } else { cout << "Result: The above string is not in the language" << endl; } system("PAUSE"); return 0; }