Consider the following pseudocode:
declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
write the stack's top character to the screen
pop a character off the stack
}
write c++ code for above
1
Expert's answer
2021-09-15T04:59:00-0400
#include<iostream>#include<stack>usingnamespace std;
intmain(){
char s[] = "geeksquiz";
stack<char>s1;
int i =0;
while(s[i]){
s1.push(s[i]);
i++;
}
while ( !s1.empty())
{
cout<<s1.top()<<" ";
s1.pop();
}
}
Comments