Professional Documents
Culture Documents
148
148
Code:
#include <iostream>
#include <stack>
using namespace std;
return i == poppedSize;
}
int main() {
int pushed[] = {1, 2, 3, 4, 5};
int popped[] = {5, 4, 3, 2, 1};
int pushedSize = sizeof(pushed) / sizeof(pushed[0]);
int poppedSize = sizeof(popped) / sizeof(popped[0]);
if (result)
{
cout << "Output: True" <<endl;
} else {
cout << "Output: false" <<endl;
}
return 0;
}
Output :
Learning Outcomes :
3 Stack Pop and Compare: The while loop inside the for loop iterates
as long as there are elements in the stack and the current element in
the pushed array matches the next element in the popped array.
4 Return Value: This means that all elements were pushed and
popped correctly, and the stack is empty. Otherwise, it returnsfalse.