Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ Complete the program for the problem. Run the program below Describe the result of executing the exception and exception handling. < < Below

In c++

Complete the program for the problem. Run the program below Describe the result of executing the exception and exception handling. << Below is a part of a program that implements Stack ADT as a single linked list. Much of the program has been omitted as needed. Answer the following questions. >>

---------------code -----------

class StackEmptyException { private: string errorMsg; public: StackEmptyException(const string& err) { errorMsg = err; } string getMessage() const { return errorMsg; } }; // class StackEmptyException template class Node { private: E element; Node* next; public: Node(const E& e, Node* n) { element = e; next = n; } friend class LinkedStack; }; // class Node template class LinkedStack { private: Node* tp; // top designation pointer public: LinkedStack(); ~LinkedStack(); LinkedStack(const LinkedStack& ls); LinkedStack& operator=(const LinkedStack& ls); // ? int size() const; // ? bool isEmpty() const; void push(const E& e); void pop() throw(StackEmptyException); const E& top() throw(StackEmptyException); }; // class LinkedStack template LinkedStack::LinkedStack() { tp = NULL; } // constructor template bool LinkedStack::isEmpty() const { return size() == 0; } template void LinkedStack::push(const E& e) { Node* v = new Node(e, tp); tp = v; } // push() template LinkedStack::~LinkedStack() { while (!isEmpty()) pop(); } // destructor int main() { int a[5]={ 1, 2, 3, 4, 5 }; LinkedStack s; for (int i=0; i<5; i++) s.push(a[i]); // the five element of a[] push() cout << "size = " << s.size() << " " << endl; LinkedStack rS(s); // using copy constucrtor for (int i=0; i<3; i++) rS.pop(); // call pop 3times s=rS; // using assigment commend cout << "Current top's element = " << s.top() << endl;

for (int i=0; i<3; i++) s.pop(); // call pop 3times

cout << "size = " << s.size() << " " << endl; }

// main()

---------------

2. Suggest and implement a method to modify the Stack ADT to execute the size () operation in O (1) only.

 I would really appreciate it if you commented on the comments. purpose: 1. Designing and Implementing Template Classes 2. Implementing destructors, copy constructors, and assignment operator overloading functions 3. Design and Implement a Single Linked List Copy Algorithm 4. Understanding the operation and characteristics of Stack ADT 5. Identify the need for exception handling and how to handle it 6. Design and implement template class modification to improve execution time of size () operation

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

Step: 3

blur-text-image

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

1.what is the significance of Taxonomy ?

Answered: 1 week ago

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago

Question

Name is needed for identifying organisms ?

Answered: 1 week ago