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

Step 1 Doubly Linked List Class From the lecture material create a doubly linked

ID: 3842304 • Letter: S

Question

Step 1 Doubly Linked List Class From the lecture material create a doubly linked list class. This class should be generic so that it will operate on any given type. Your class should have the ability to add to the front, add to the rear, insert (you can insert before or after a node), delete, and find. Your list class should also implement functionality that will allow you traverse the list forward and backward. As for the naming conventions and interface into the list Iwill leave all of that up to you. Step 2 Stack and Queue Using the linked list class you created in Step 1 create stack and queue classes. I will leave it up to you as to whether to use composition or inheritance but whatever way you choose to go you should be able to explain why you chose the relationship type you did. The stack class should have the following interface push pop peek. The queue should have the following interface en queue dequeue peek Again I will leave it up to you as to the parameters to the functions and the return type. As usual please have good reasoning for why you have been doing things

Explanation / Answer

#include using namespace std; class Stack { public: Stack(); ~Stack(); void push(int); int pop(); int peek(); friend void print(Stack&); private: typedef struct node { node *next; int data; } NODE; NODE *top; }; Stack::Stack() { top = NULL; } Stack::~Stack() { while(top) { NODE *tmp = top; top = top->next; delete tmp; } } void Stack::push(int n) { NODE *ptr = new NODE; ptr->next = top; ptr->data = n; top = ptr; } int Stack::pop() { NODE *tmp = top; int val = top->data; top = top->next; delete tmp; return val; } int Stack::peek() { return top->data; } void print(Stack &s;) { Stack::NODE *cur = s.top; while(cur) { cout push(30); st->push(40); st->push(50); print(*st); st->pop(); st->pop(); print(*st); 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