checking if a string is within a language

I need a bit of help with a homework problem. I think I have a good start I am unsure how to break up a string letter by letter so that I can push it into a stack. This is the exact question and the code I have made so far:

Write a function that uses a stack (i.e. it has a stack as a local variable) to determine whether a string is in the language L, where:

L = {ww' : w is a string of characters, w' = reverse(w)}




1
2
3
4
5
6
7
8
9
bool isIn (const string w)
{
	if ((w.length() % 2 == 1) || (w.length() < 2) || (w.isEmpty))
		return false;

	else {
		while (!(w.isEmpty))
		push() //how do you break up the string??
}

using the string class you can index a string(kinda like an array

for example:

string name = "Brandon";

name.at(0) // would return "B"
name.at(1) // would return "r"
etc...

so if you want to split up the string, use a loop or something and push onto the stack the variablename.at(i)

I hope this was clear and relative to what you were asking.
That was the perfect answer, thank you very much!
Topic archived. No new replies allowed.