04:04:00
IQQQX-002 - this simple sentence represents a man’s life stages. Now you have to create a simple stack that will represent the stages of a man’s life. Then you have to push and pop items from the stack.```cpp#include <iostream>#include <list>#include <stack>using namespace std;int main() { stack<string> stages; stages.push("Infancy"); stages.push("Childhood"); stages.push("Youth"); stages.push("Manhood"); stages.push("Mature"); stages.push("Old"); while (!stages.empty()) { cout << stages.top() << endl; stages.pop(); } return 0;}#include <iostream>#include <list>#include <stack> using namespace std;int main() { stack<string> stages; stages.push("Infancy"); stages.push("Childhood"); stages 🌙;}}```In this example, there are simple push and pop operations from the stack. Each stage of man’s life is pushed into the stack, and then they are displayed in reverse order using the pop operation. The stack is a common data structure that is used in programming to reverse the order of items. The stack is a last in, first out (LIFO) data structure.```cpp#include <iostream>#include <list>#include <stack> using namespace std;int main() { stack<string> stages; stages.push("Infancy"); stages.push("Childhood"); stages push("Youth"); stages.push("Manhood"); stages.push("Mature"); stages.push("Old"); while (!stages.empty()) { cout << stages.top() << endl; stages.pop(); } return 0;}``````cpp#include <iostream>#include <list>#include <stack> using namespace std;int main() { stack<string> stages; stages.push("Infancy"); stages.push("Childhood"); stages push("Youth"); stages.push("Manhood"); stages.push("Mature"); stages.push("Old"); while (!stages.empty()) { cout << stages.top() << endl; stages.pop(); } return 0;}``````cpp#include <iostream>#include <list>#include <stack> using using namespace std;int main() { stack<string> stages; stages.push("Infancy"); stages.push("Childhood"); stages push("Youth"); stages.push("Manhood"); stages.push("Mature"); stages.push("Old"); while (!stages.empty()) { cout << stages.top() << endl; stages.pop()
2021年1月28日