Menu

[Solved]Template Dequeue Class C Assignment Use Given Test Menu Template Deque Class Linked List B Q37103380

Template Dequeue Class (C++ )

In this assignment, we will use a given test menu for thetemplate Deque Class (a Linked List based Double Ended Queue,Deque) that you have put together.

Starter

testDeque.cpp which contains:

  1. Timer class holder (you need to go through the LearnCpp Ch15and import it in)
  2. Node class
  3. Deque class specification (you need to fill out thedefinition)

here is the testDeque.cpp code:

// C++ implementation of doubly linked list Deque doubly linkedlist#include <bits/stdc++.h>using namespace std;class Timer {// To replace with the full timer class definition// inside this folder: LearnCpp9_18_timeSortArray.cpp};// Node of a doubly linked listtemplate<class T>class Node {public:T data;Node<T> *prev, *next;static Node<T>* getnode(int data) {Node<T>* n = new Node<T>;n->data = data;n->prev = n->next = nullptr;return n;}};// A doubly linked list dequetemplate<class T>class Deque {Node<T> *head, *tail, *copy;int size;// deep copy helpervoid deepCopy( const Deque<T> & rhs );public:Deque():head(nullptr), tail(nullptr), size(0) { }Deque( const Deque<T> & rhs ); // copyconstructorDeque( Deque<T> && rhs ); // moveconstructorDeque<T> & operator= ( Deque<T> & rhs ); //copy operator=Deque<T> & operator= ( Deque<T> && rhs); // move operator=// Operations on Dequevoid pushHead(T data);void pushTail(T data);void popHead();void popTail();void erase();T getFront();T getRear();int _size() { return size; }bool isEmpty() { return !head; }T operator[] (const int &sub);};template<class T>void Deque<T>::deepCopy( const Deque<T> & rhs ){Node<T> *newNode = new Node<T>;Node<T> *current = rhs.head; //current points to the listto be copiedsize = rhs.size;//copy the head nodecopy = newNode; //create the nodecopy->data = current->data; //copy the infocopy->next = current->next; //set the link field of thenode to nullptrcopy->prev = current->prev;tail = head; //make tail point to the head nodecurrent = current->next; //make current point to the nextnode//copy the remaining listwhile (current != nullptr) {newNode = new Node<T>; //create a nodenewNode->data = current->data; //copy the infonewNode->next = current->next;newNode->prev = current->prev;tail->next = newNode;tail = newNode;current = current->next;}}// complete the rest of definitions below// Driver program to test the Link List Deque classint main() {Deque<int> dq;cout << “nInsert item ‘5’ at tail”;dq.pushTail(5);cout << “nInsert item ’10’ at tail”;dq.pushTail(10);cout << “nRear item: ” << dq.getRear();dq.popTail();cout << “nAfter deleting tail item, new tail is “<< dq.getRear();cout << “nInserting item ’15’ in head”;dq.pushHead(15);cout << “nFront item: ” << dq.getFront()<< “nNumber of items in Deque: ” <<dq._size();dq.popHead();cout << “nAfter deleting head item new head is “<< dq.getFront();dq.popHead();cout << “nAfter deleting head item new head is “<< dq.getFront();cout << “nInitializing a 10000 item Deque.”;Timer t1;for(int i=1; i<=10000; i++) dq.pushTail(i);cout << “nAdd 1~10000, dq now has “<< dq._size() << ” items.”;double run1 = t1.elapsed();cout << “nTime elipsed: ” << run1 << “seconds”;Timer t2;cout << “nDeep Copy construct dq2”;Deque<int> dq2( dq );double run2 = t2.elapsed();cout << “nTime elipsed: ” << run2 << “seconds”<< “ndq2 front to rear: ” << dq2.getFront()<< ” to ” << dq2.getRear();cout << “nMove construct dq3”;Timer t3;Deque<int> dq3(std::move(dq));double run3 = t3.elapsed();cout << “nTime elipsed: ” << run3 << “seconds”<< “ndq3 front to rear: ” << dq3.getFront()<< ” to ” << dq3.getRear();cout << “ndq2[0] is ” << dq2[0]<< “, dq2[999] is ” << dq2[999];}

Make sure you have implemented and validated the Stack/Queuemember functions especially the following additional methods for AS9:

  • subscription operator [ ] read and write (includedinstarter)
  • subscription over the range exception (included instarter)

Example Test Driver

// Driver program to test the Link List Deque class int main() { Deque dq; cout << “nInsert item ‘5’ at tail”; dq.pushTail(5); cout << “nInsert item ’10’ at tail”; dq.pushTail(10); cout << “nRear item: ” << dq.getRear(); dq.popTail(); cout << “nAfter deleting tail item, new tail is ” << dq.getRear(); cout << “nInserting item ’15’ in head”; dq.pushHead(15); cout << “nFront item: ” << dq.getFront() << “nNumber of items in Deque: ” << dq._size(); dq.popHead(); cout << “nAfter deleting head item new head is ” << dq.getFront(); dq.popHead(); cout << “nAfter deleting head item new head is ” << dq.getFront(); cout << “nInitializing a 10000 item Deque.”; Timer t1; for(int i=1; i<=10000; i++) dq.pushTail(i); cout << “nAdd 1~10000, dq now has ” << dq._size() << ” items.”; double run1 = t1.elapsed(); cout << “nTime elipsed: ” << run1 << ” seconds”; Timer t2; cout << “nDeep Copy construct dq2”; Deque dq2( dq ); double run2 = t2.elapsed(); cout << “nTime elipsed: ” << run2 << ” seconds” << “ndq2 front to rear: ” << dq2.getFront() << ” to ” << dq2.getRear(); cout << “nMove construct dq3”; Timer t3; Deque dq3(std::move(dq)); double run3 = t3.elapsed(); cout << “noisy()Time elipsed: ” << run3 << ” seconds” << “ndq3 front to rear: ” << dq3.getFront() << ” to ” << dq3.getRear(); cout << “ndq2[0] is ” << dq2[0] << “, dq2[999] is ” << dq2[999]; }

Sample Test Run

Running/home/ubuntu/workspace/comsc200/W Insert item .5 at tail Insert item 10 at tail Rear item: 10 After deleting tail i

Submit

  1. AS10_testDeque.cpp
  2. Deque.h and Timer.h
  3. test run validation

Running/home/ubuntu/workspace/comsc200/W Insert item .5′ at tail Insert item ’10’ at tail Rear item: 10 After deleting tail item, new tail is 5 Inserting item ’15’ in head Front item: 15 Number of items in Deque: 2 After deleting head item new head is 5 After deleting head item new head is 0 Initializing a 10000 item Deque. Add 1~10000, dq now has 10000 items. Time elipsed: 0.000719669 seconds Deep Copy construct dq2 Time elipsed: 0.000580651 second Move construct dq3 Time elipsed: Љ75e ar seconds dq3 front to rear: 1 to 10000 dq2 [0] is 1, dq2 [999] is 1000 Process exited with code: Show transcribed image text Running/home/ubuntu/workspace/comsc200/W Insert item .5′ at tail Insert item ’10’ at tail Rear item: 10 After deleting tail item, new tail is 5 Inserting item ’15’ in head Front item: 15 Number of items in Deque: 2 After deleting head item new head is 5 After deleting head item new head is 0 Initializing a 10000 item Deque. Add 1~10000, dq now has 10000 items. Time elipsed: 0.000719669 seconds Deep Copy construct dq2 Time elipsed: 0.000580651 second Move construct dq3 Time elipsed: Љ75e ar seconds dq3 front to rear: 1 to 10000 dq2 [0] is 1, dq2 [999] is 1000 Process exited with code:

Expert Answer


Answer to Template Dequeue Class (C++ ) In this assignment, we will use a given test menu for the template Deque Class (a Linked L… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *