+ 1
Stack
How can I reverse a name with stack??
2 Respostas
+ 4
If you name is stored in a character array, then you need to iterate over the string/char array and add its elements to an std::stack object. Then create a new empty string and empty the stack. Due to the stack's LIFO nature, the stack data will be retrieved in reverse, which can be appended to your string.
The loop will look like:
string rev;
while(!stk.empty())
{
rev+=stk.top(); stk.pop();
}
+ 1
thanks🙏😇