Question: Use the following declarations template class stack { private: T elt[n]; int counter; public: void CreateStack() { counter = 0; } void IsEmpty() { if
Use the following declarations
template
class stack
{
private: T elt[n];
int counter;
public:
void CreateStack() { counter = 0; }
void IsEmpty() { if (counter == 0) return true; else return false; }
void IsFull() { if (counter == n) return true; else return false; }
void push(T x) { elt[counter] = x; counter++; }
T pop() { --counter; return elt[counter]; }
};
Write a complete program to do the following in the same order
(i) Create stack ALL of size 10 and int type
(ii) Store 10 random numbers <= 50 in stack ALL
(iii) Display stack ALL and collect all even numbers in stack EVEN and odd numbers in stack ODD
(iv) Display both stack EVEN and ODD.The order of the numbers must be the same as their order in stack ALL
Sample I / O
Stack ALL : 22 55 33 40 50 17 13 21 44 15
Stack ODD : 15 21 13 17 33 55
Stack EVEN : 44 50 40 22
This is C++ Program Please make sure it work on Visual Studio.Thank You!!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
