Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!