Implement a template-based stack using a variable-sized dynamic array

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ code

 Stack Implementation using Variable-sized Dynamic Arrays
2. Stack Implementation using Linked Lists
3. The applications of Stacks
1. Implement a template-based stack using a variable-sized dynamic array. When the array gets
full, double its size before insertion of new elements. When array contains data lesser than
33% of its size, reduce its size to half. The required member methods are:
T* arr: array containing data elements of stack
int capacity: stores the capacity of stack.
int getCout(): returns total elements stored in the stack.
bool isEmpty(): returns true if the stack is empty else false.
bool isFull(): returns true if the stack is full.
bool top(): returns, but does not delete, the topmost element from the stack via the
parameter passed by reference, and returns true via the return statement. If there is no
element, it returns false via the return statement.
bool pop(): deletes the top most element from the stack and returns true via the return
statement. If there is no element, it returns false.
bool push(T const& e): pushes the element “e” on top of the stack if there is some space
available, and returns true via the return statement. Otherwise, If there is no capacity in the
stack than call resize function to increase the capacity of stack.
void reSize() This function will double the size of stack.
Optional (This function should also reduce the size of stack by half if the count of elements
is less than 25% of the total capacity).
2. Implement a template-based stack using linked list. Maintain the head pointer in the stack
class. The required members and methods are:
int size(): returns total elements stored in the stack
bool isEmpty(): returns true if the stack is empty else false.
bool top(T& data): returns, but does not delete, the topmost element from the stack via
the parameter passed by reference, and returns true via the return statement. If there is no
element, it returns false.
bool pop(): deletes the top most element from the stack and returns true via the return
statement. If there is no element, it returns false.
void push(T const& e): pushes the element “e” on top of the stack.
(optional) ReverseString (String s): this method should reverse the parameter string.
3. Given an expression containing opening and closing braces, brackets, and parentheses;
implement a global function “isBalanced” to check whether the given expression is a
balanced expression or not, using your stack implementation. For example, {[{}{}]}[()], {{}{}},
and []{}() are balanced expressions, but {()}[) and {(}) are not balanced. In your main function
test your function using the given examples.
bool isBalanced(string exp)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY