Question: DLL: #ifndef __DLL_H__ #define __DLL_H__ #include exceptions.h class DllNode { public: int value; DllNode *prev; DllNode *next; }; class Dll { private: DllNode *head; int

 DLL: #ifndef __DLL_H__ #define __DLL_H__ #include "exceptions.h" class DllNode { public:int value; DllNode *prev; DllNode *next; }; class Dll { private: DllNode

DLL:

#ifndef __DLL_H__ #define __DLL_H__

#include "exceptions.h"

class DllNode { public: int value; DllNode *prev; DllNode *next; };

class Dll { private: DllNode *head; int _size; public: Dll(); // create an empty list Dll(const Dll &src); // create a deep copy of the src list Dll(const int arr[], int size); // create a linked list containing the elements of the array Dll &operator=(const Dll &src); // create a deep copy of the src list ~Dll(); // free all memory

bool empty() const; // return if the list is empty in O(1) int size() const; // return how many items are in the list in O(1)

int &at(int rank); // return a reference to the value of the list at a rank/index void insert(int rank, int value); // insert a value at the rank/index int remove(int rank); // remove the node at the rank/index and return its value

void clear(); // reset the list to an empty list void display(ostream &os) const; // write the contents of the list to the ostream };

ostream &operator

#endif

Stack:

#ifndef __STACK_H__

#define __STACK_H__

#include "exceptions.h"

#include "dll.h"

class Stack {

private:

Dll store;

public:

Stack(); // create an empty stack

void push(int value); // add an item to the top of the stack

int pop(); // remove of the value at the top of the stack and return its value

int peek(); // return the value at the top of the stack, keeping it in the stack

int size() const; // return how many items are in the stack

bool empty() const; // return if the stack is empty

void display(ostream &os) const; // write the contents of the stack to the ostream

};

ostream &operator

#endif

.cpp file:

#include

#include "exceptions.h"

#include "dll.h"

#include "stack.h"

using namespace std;

int main() {

try {

string ch;

cout

cin >> ch;

if (ch == "l") {

cout

string choice;

int rank;

int val;

Dll list;

while (1) {

cout

cin >> choice;

if (choice == "q") {

break;

}

if (choice == "i") {

cin >> rank >> val;

list.insert(rank, val);

}

else if (choice == "r") {

cin >> rank;

cout

}

else if (choice == "a") {

cin >> rank;

cout

}

else if (choice == "s") {

cout

}

else if (choice == "c") {

list.clear();

}

else if (choice == "e") {

cout

}

}

}

else if (ch == "s") {

cout

string choice;

int val;

Stack stack;

while (1) {

cout

cin >> choice;

if (choice == "q") {

break;

}

if (choice == "push") {

cin >> val;

stack.push(val);

}

else if (choice == "pop") {

cout

}

else if (choice == "peek") {

cout

}

else if (choice == "size") {

cout

}

else if (choice == "empty") {

cout

}

}

}

}

catch (InvalidOperationException &e) {

cout

}

catch (IndexOutOfRangeException &e) {

cout

}

return 0;

}

For this project, you are to implement two abstract data types (ADTS). You will write doubly linked list (011) and stack (Stack) class. The stack will use the dll internally. The class interfaces are downloadable below. You must follow the interface exactly. While you can define other public and private methods and fields, the class names and methods given must appear as provided, or you will not pass the unit tests. Include the implementation of the classes in their respective header (.h) files. Please note: Dll is not a node class, as in, a Dll does not point to another dll; it contains nodes internally. Dll Comments When inserting into a dll, rank o inserts at the front of the list and rank size() inserts at the back of the list. If you have the list 0-> 10->30, then after insert(2, 20), the list should be 0 -> 10-> 20-> 30. When removing from a dll, rank o removes from the front of the list and rank size() - 1 removes from the back of the list. If you have the list 0->10-> 20-> 30, then after remove(2), the list should be 0-> 10-> 30. When building a dll from an array, the array [012] should create the list 0 -> 1->2. Displaying When displaying a D11, it should appear with the head on the left and the tail on the right. For example, the list created after insert(e, 3), insert(0, 2), insert(0, 1) should represent the list 7 -> 2-> 3 and should display as follows: [ 1 2 3] When displaying a Stack, it should appear with the top on the left and the bottom on the right. For example, the stack created after push(1), push(2), push(3) should display as follows: [ 321] When displaying an empty ADT, it should be a single space surrounded by brackets: [ [] Efficiency All operations should have an efficient runtime. Besides display(), all stack operations should run in 0(1). Exceptions Two exception classes can be found in exceptions.h: InvalidOperationException and IndexOutOfRange Exception. Your ADTs will throw exceptions according to the instructions below: Dll: throw IndexOutOfRangeException for the following operations: at(): when accessing an index outside the bounds (0 to size-1 inclusive) of the linked list with the message "at(): Index was outside the bounds of the linked list." insert(): when index is not in the range from 0 to size (inclusive) with the message "insert(): Index was outside the bounds of the linked list" remove(): when removing an index outside the bounds (to size-1 inclusive) of the linked list with the message "remove(): Index was outside the bounds of the linked list." Stack: throw InvalidoperationException with the message "Stack empty." when popping or peeking an empty stack. p3.cpp p3.cpp is a command-line interface that can be used to test your data structures. Review the code before running it and testing your data structures.p3.cpp assumes your dll.h and stack.h are completed. You must comment out the portions of the code that you have not implemented (includes and the loops in main pertaining to the data structure) or create 'empty" method definitions to make it compilable. You can compile your program with g++ p3.cpp. Notes . Your data structures will be unit tested separately, meaning Dll can be tested accurately without a fully implemented Stack Be sure to print to the ostream os variable and not to cout or you will fail the test cases. Throw the exceptions if the index is negative Be sure to initialize pointers to NULL or nullptr as *nix environments do not initialize variables too. Be sure to use Submit mode and Submit for grading on the tester to verify the format and that your project works in a *nix environment

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!