Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include template class stackType { public: stackType(int stackSize = 100); ~stackType(); void initializeStack(); bool isEmptyStack() const; bool isFullStack() const; void push(const T&

#include #include #include #include

template class stackType { public: stackType(int stackSize = 100); ~stackType(); void initializeStack(); bool isEmptyStack() const; bool isFullStack() const; void push(const T& newItem); void push(const std::vector& newItems); void pop(); T top() const;

private: int maxStackSize; int stackTop; std::vector list; };

template stackType::stackType(int stackSize) { if (stackSize <= 0) { stackSize = 100; } maxStackSize = stackSize; stackTop = 0; list.resize(stackSize); }

template stackType::~stackType() { }

template void stackType::initializeStack() { stackTop = 0; }

template bool stackType::isEmptyStack() const { return (stackTop == 0); }

template bool stackType::isFullStack() const { return (stackTop == maxStackSize); }

template void stackType::push(const T& newItem) { if (isFullStack()) { throw std::runtime_error("Stack is full."); } list[stackTop] = newItem; stackTop++; }

template void stackType::push(const std::vector& newItems) { int size = newItems.size(); if (stackTop + size > maxStackSize) { throw std::runtime_error("Stack overflow."); } for (int i = 0; i < size; i++) { list[stackTop + i] = newItems[i]; } stackTop += size; }

template void stackType::pop() { if (isEmptyStack()) { throw std::runtime_error("Stack is empty."); } stackTop--; }

template T stackType::top() const { if (isEmptyStack()) { throw std::runtime_error("Stack is empty."); } return list[stackTop - 1]; }

#include

int main() { std::queue> stacks; stackType stack1(50); stackType stack2(50); std::vector values = { 23, 45, 38 };

try { stack1.initializeStack(); stack1.push(values); stack2.initializeStack(); stack2.push(values);

stacks.push(stack1); stacks.push(stack2);

while (!stacks.empty()) { stackType currentStack = stacks.front(); stacks.pop();

while (!currentStack.isEmptyStack()) { int value = currentStack.top(); currentStack.pop(); std::cout << value << " "; } std::cout << std::endl; } }

return 0;

i am geting an error

E0530

hellp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions