Question: The stack and node classes are below. Stack.h: #ifndef NODEB_STACK_H #define NODEB_STACK_H #include Node.h #include using namespace std; template typename Object> class Stack { private

 The stack and node classes are below. Stack.h: #ifndef NODEB_STACK_H #define

The stack and node classes are below.

Stack.h:

#ifndef NODEB_STACK_H #define NODEB_STACK_H #include "Node.h" #include  using namespace std; templatetypename Object> class Stack { private:  Node* top; public:  Stack() {  top = nullptr; }  ~Stack() {  while (!isEmpty()) { pop(); } } bool isEmpty() const { return (top == nullptr); } void push(Object item) { if (isEmpty()) {  Node* newNode = new Node(item);  top = newNode; } else {  Node* newNode = new Node(item, top);  top = newNode; } } Object pop() { if (isEmpty()) {  return Object(); } else {  Object copy = top->getItem();  Node* topCopy = top;  top = top->getNext();  delete topCopy; // Return the Object  return copy; } } bool exists(Object item) const { Node* curr = top; while (curr != nullptr) {  if (curr->getItem() == item) {  return true; } curr = curr->getNext(); }  return false; } void printStack() const { Node* curr = top; while (curr != nullptr) {  cout getItem() getNext(); } } };  

Node.h:

templatetypename Object> class Node { private: Object item; Node* next; public: Node(Object newItem) { item = newItem; next = nullptr; } Node(Object newItem, Node* nextNode) { item = newItem; next = nextNode; } void setItem(Object newItem) { item = newItem; } Object getItem() const { return item; } void setNext(Node* nextNode) { next = nextNode; } Node* getNext() const { return next; } };

Stack Class Start with the Stack class from lecture. What is the Big-Oh complexity of the methods? Queue Class Create a Queue class that uses the Node class from lecture to create a functioning queue data structure. . Your Queue should be able to push and pop Objects and determine if an Object is in the Queue. What is the complexity of each method? . Your Queue must be able to be used with any data type. Your Nodes must be stored in heap memory. . Your program must not have any memory leaks. Stack Class Start with the Stack class from lecture. What is the Big-Oh complexity of the methods? Queue Class Create a Queue class that uses the Node class from lecture to create a functioning queue data structure. . Your Queue should be able to push and pop Objects and determine if an Object is in the Queue. What is the complexity of each method? . Your Queue must be able to be used with any data type. Your Nodes must be stored in heap memory. . Your program must not have any memory leaks

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!