C++ #include #include using namespace std; class Stack { private: vector vec; p

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

C++ #include #include using namespace std; class Stack { private: vector vec; p

Post by answerhappygod »

C++
#include <iostream>#include <vector>
using namespace std;
class Stack { private: vector<int> vec; public: void push(int n) { vec.push_back(n); }
int pop() { int n = vec[vec.size() -1]; vec.pop_back(); return n; }
int top() { return vec[vec.size() -1]; }
bool isEmpty() { return vec.empty(); }
int size() { return vec.size(); } };
int main() { Stack s; for (int i = 0; i < 5; ++i) { s.push(i); } cout << "Stack contains" <<endl; while (!s.isEmpty()) { cout << s.pop()<< endl; } return 0; }
Repeat the following programming problem above, butafter the first doubling of the array, halve the size of the arrayif fewer than half of the array’s locations are occupied by currentstack entries.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply