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

Please write a C++ program for a class stack template using the following skelet

ID: 3808841 • Letter: P

Question



Please write a C++ program for a class stack template using the following skeleton. The 2nd picture is the testing, that will be in the main routine. If you could include screenshots that would be a plus. Thank you kindly for the help.

Part t dar March Part 2 due date April 4, 20 Linked list the implementation of stack and eaese. Especially is perfect data stnacture for manipulation for a for the queue, it avoids the of wrappin impiemem bonh an amay. In this project. you are requested to slack and queue by using linked list (not an amay). Program 1 implement a template class stack as defined by the following skeleton: templatesclass Item Type class Stack private Node Type ItemType topPrr, points to a singly linked list public: stack(): default constructor stack is created and empty for a Stack(const Stack item Type &x.; copy constructor: implicitly called deep copy -void MakeEmptyo; Stack is made emptyi you should deallocate all the the nodes of the linked list test if the stack is empty bool Empty(); test if the stack is full, assume MAXITEM-5 bool Is Full return the number of elements in the stack int length(); print the value of all elements in the stack in the void Print() sequence from the top to bottom void Push(ItemType x); /l insert x onto the stack void Pop (ItemType &x;: delete the top element from the stack Precondition: the stack is not empty i Destructor: memory for nodes dealocated Stack(); template class ItemType struct Node Type Item Type info; Node Type* next.

Explanation / Answer

Queue:

#include<iostream>

#include<cstdlib>

using namespace std;

struct node{

int info;

struct node *next;

};

class Queue{

private:

node *rear;

node *front;

public:

Queue();

void enqueue();

void dequeue();

void display();

};

Queue::Queue(){

rear = NULL;

front = NULL;

}

void Queue::enqueue(){

int data;

node *temp = new node;

cout<<"Enter the data to enqueue: ";

cin>>data;

temp->info = data;

temp->next = NULL;

if(front == NULL){

front = temp;

}else{

rear->next = temp;

}

rear = temp;

}

void Queue::dequeue(){

node *temp = new node;

if(front == NULL){

cout<<" Queue is Emtpty ";

}else{

temp = front;

front = front->next;

cout<<"The data Dequeued is "<<temp->info;

delete temp;

}

}

void Queue::display(){

node *p = new node;

p = front;

if(front == NULL){

cout<<" Nothing to Display ";

}else{

while(p!=NULL){

cout<<endl<<p->info;

p = p->next;

}

}

}

int main(){

Queue queue;

int choice;

while(true){

cout<<" 1.Enqueue 2. Dequeue 3. Display 4.Quit";

cout<<" Enter your choice: ";

cin>>choice;

switch(choice){

case 1:

queue.enqueue();

break;

case 2:

queue.dequeue();

break;

case 3:

queue.display();

break;

case 4:

exit(0);

break;

default:

cout<<" Invalid Input. Try again! ";

break;

}

}

return 0;

}

Stack: