C++
1. Set array size to 5
2. Within your main() method,
a. push the following values onto the stack: 2, 4, 5, 6, 8, 10, 12
b. Display what is returned from peek(), and then pop() the stack
c. repeat b. above until the stack is empty.
Here I am sending code, screens of code and output. Please refer the screens. If any queries or question comment below. Thank you.
Cpp Code:
#include <iostream>
using namespace std;
int stack[5], top = -1; //declaring array size with 5.
int main()
{
int val; //declaring variable.
cout<<"Enter values to push: "; //prompting the user to enter values to push.
/*push the values in to the stack.*/
for(int i=0; i<5; i++)
{
cin>>val; //reading the values
stack[++top] = val; //push in to the stack.
}
/*displaying peek and popping the stack.*/
for(int i=4; i>=0; i--)
{
cout<<stack[top]<<"\n"; //displaying peek element.
top--; //popping the stack.
}
return 0;
}

output:

C++ 1. Set array size to 5 2. Within your main() method, a. push the following...