Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make sure it’s a implementation of stack using DOUBLY LINKED LIST. Write a C++ c

ID: 3744814 • Letter: M

Question

Make sure it’s a implementation of stack using DOUBLY LINKED LIST. Write a C++ class (or a set of classes) that implements a stack using a double linked list. The type of data contained in the stack should be int. The maximum size of the stack is 50. Implement the following methods: Constructor and destructor;// 5 points void push (int value):// pushes an element with the value into the stack. 5 points int pop 0:// pops an element from the stack and returns its value. 10 points int isEmpty:// returns 1 if the stack is empty, 0 otherwise. 5 points . int numOfElements0:// returns the number of elements in the stack. 5 points void printElements0;// print out the current stack to the console. 5 points A main function;// execute each method of your stack (except the destructor) at least once without asking input from the users. 15 points.

Explanation / Answer

#include using namespace std; struct Node { int data; Node *next; Node *prev; }; class Stack { private: Node *head; public: Stack() { head = NULL; } ~Stack() { Node *temp = head, *next; while(temp != NULL) { next = temp->next; delete temp; temp = next; } } void push(int value) { Node *n = new Node; n->data = value; n->next = head; n->prev = NULL; if(head != NULL) { head->prev = n; } head = n; } int pop() { int n = head->data; head = head->next; head->prev = NULL; return n; } int numOfElements() { Node *temp = head; int count = 0; while(temp != NULL) { count++; temp = temp->next; } return count; } void printElements() { Node *temp = head; while(temp != NULL) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote