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

mplement the Back-end of an ADT that represents a stack. The class contains two

ID: 3686810 • Letter: M

Question

mplement the Back-end of an ADT that represents a stack. The class contains two pointers that maintain key locations in The Doubly-Linked list. Node *headPtr; // Pointer to first node in the chain; Node *topPtr; // Pointer to (last) node in the chain that contains the stack's top You must write code in the class DLinkedStack, inside DLinkedStack.h. The functions that are to be implemented by you are marked with a //TODO Constraints The class should support the following types via templates: int The Class must use Node from Node.h to represent a node.

Explanation / Answer

Sample code for stack using Doubly linked list

Sample code for list header

#ifndef STACK_H
#define STACK_H

#include "iostream"

using namespace std;

struct node{
public:
string name;

string course;

node* next;

node* prev;

};

class list{

public:

static node* newnode();

//static void node* searchnode();

static note* deletenode();

static node* display();

private:

static node* firstnode;

static node* lastnode;

};

#endif

Sample code for list

#include "iostream"

#include "stack.h"

using namespace std;

node* list::newnode()

{

node* nodehold;

nodehold = new node;

cout << endl << "Enter the Name:";

cin >> nodehold->name;

cout << endl << "Enter the Cource:";

cin >> nodehold->course;

if(firstnode == NULL)

{

firstnode = nodehold;

lastnode = nodehold;

nodehold->next = NULL;

nodehold->prev = NULL;

return nodehold;

}

if(firstnode != NULL)
{

nodehold->next = lastnode;

nodehold->prev = NULL;

return nodehold;

}

}

node* list::deletenode()

{

node *nodehold;

nodehold = firstnode;

firstnode = firstnode->next;

delete nodehold;

return;

}
//node* list::searchnode()

//{

//}

node* list::display()

{

node* nodehold;

if(firstnode == NULL)

{

cout << endl << "There are no nodes in list";

return;

}

else

{

nodehold = firstnode;

while(nodehold != NULL)

{

cout << endl <<"Name:"<< nodehold->name << " Course:" << nodehold->course;

nodehold=nodehold->next;

}

cout << endl << "End of list";

}

}

sample code for mainlist


#include "iostream"

#include "stack.h"

using namespace std;

void main()

{

int option;

//node list::firstnode=NULL;

//node list::lastnode=NULL;

firstnode=NULL;

lastnode=NULL;

do

{

cout << "Please select an option :" << endl;

cout << "0. Exit the program." <<endl;

cout << "1. Add a node" << endl;

cout << "2. Delete node from the list." << endl;

//cout << "3. search node from the list." << endl;

cout << "4. display node from the list." << endl;

cout << endl << " >> ";

switch (option)

{

case 1 : node* list::newnode();

break;

case 2 : node* list::deletenode();

break;

//case 3 : node* list::searchnode();

// break;

case 4 : node* list::display();

break;

}

}while(option != 0);

}

note-the above code with required modifications can help to answer the given question.