mplement
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Topic: Doubly Linked List Deque
Implement the following problem in the main case 0 (see attached photo)
Your algorithm for the hierarchy problem should follow this: Evaluate the final set of operations first given the set of rules. Then, do the remove operations. Finally, do the add operations.
DO NOT MIND THE #include "dlldeque.h" it is already implemented only the case 0 needs to be solved
#include <iostream>
#include <cstring>
#include "dlldeque.h"
using namespace std;
int main(int argc, char** argv) {
DLLDeque* deque = new DLLDeque();
int test;
cin >> test;
switch (test) {
case 0:
// perform your Hierarchy implementation here
// utilize the deque initialized,
// initialize variables you need before switch
// you can use the print() method to debug, but not the final_print()
// do not modify from this point onwards
deque->final_print();
break;
case 1:
deque->addFirst(50);
deque->addLast(70);
deque->addFirst(90);
cout << deque->removeFirst() << endl;
cout << deque->removeLast() << endl;
cout << deque->removeLast() << endl;
cout << deque->isEmpty() << endl;
deque->final_print();
break;
case 2:
deque->addFirst(5);
deque->addFirst(3);
cout << deque->removeFirst() << endl;
cout << deque->removeLast() << endl;
deque->addLast(7);
deque->addFirst(9);
deque->addLast(4);
cout << deque->removeLast() << endl;
deque->addLast(6);
deque->addFirst(8);
cout << deque->removeFirst() << endl;
cout << deque->size() << endl;
deque->final_print();
break;
case 3:
deque->addFirst(19);
deque->addFirst(47);
deque->addFirst(67);
cout << deque->removeLast() << endl;
deque->addLast(17);
cout << deque->removeFirst() << endl;
cout << deque->removeFirst() << endl;
deque->addLast(4);
deque->addFirst(30);
cout << deque->size() << endl;
deque->final_print();
break;
case 4:
deque->addFirst(41);
cout << deque->removeLast() << endl;
deque->addLast(97);
deque->addLast(6);
deque->addFirst(11);
cout << deque->removeLast() << endl;
cout << deque->removeFirst() << endl;
deque->addLast(37);
deque->addFirst(38);
deque->addFirst(40);
cout << deque->removeLast() << endl;
deque->addFirst(91);
cout << deque->size() << endl;
deque->final_print();
break;
case 5:
deque->addLast(2);
cout << deque->removeFirst() << endl;
deque->addFirst(48);
deque->addFirst(22);
deque->addLast(39);
deque->addLast(81);
deque->addFirst(77);
cout << deque->removeFirst() << endl;
cout << deque->removeFirst() << endl;
deque->addFirst(34);
deque->addFirst(25);
cout << deque->removeLast() << endl;
cout << deque->removeFirst() << endl;
cout << deque->size() << endl;
deque->final_print();
break;
case 6:
deque->addFirst(11);
deque->addLast(19);
deque->addLast(82);
deque->addFirst(89);
deque->addFirst(55);
cout << deque->removeFirst() << endl;
cout << deque->removeLast() << endl;
deque->addFirst(50);
cout << deque->removeLast() << endl;
cout << deque->removeFirst() << endl;
deque->addLast(19);
deque->addFirst(15);
cout << deque->size() << endl;
deque->final_print();
break;
}
return 0;
}

Transcribed Image Text:In the Hierarchy Problem, you are given a set of numbers. Before
adding a number, sum up the digits of the number and consider the
following:
• Rule of 2: If the sum is divisible by 2, add the number to the
first.
• Rule of 3: If the sum is divisible by 3, remove the first and add
the number to the last.
• Rule of 5: If the sum is divisible by 5, remove the last and add
the number to the first and the last.
Rule of 7: If the sum is divisible by 7, remove both the first and
the last and add the number to the first.
• Rule of X: If the sum does not fall on any one of the following,
add the number to the last.
Statute of Limitations: If a sum is true to more than one of the
following, only apply two of the following rules starting from
the first mentioned rule. You can only remove and add at most
one number from each side of the deque so if two rules
combined tells you to remove the first twice as in Rule of 3 and
Rule of 7, only remove one; the similar is true for adding the
number.
• Gatekeeper: If you encounter a zero (0), stop the loop.
Note: Be careful in removing from an empty deque. With this
problem, you will have to consider improving your remove methods
for this to only return O when you attempt to remove from an empty
deque.

Transcribed Image Text:int main(int argc, char** argv) {
DLLDeque* deque
int test;
cin >> test;
switch (test)
= new DLLDeque ();
case 0:
// perform your Hierarchy implementation here
// utilize the deque initialized,
// initialize variables you need before switch
// you can use the print() method to debug, but not the final_print()
// do not modify from this point onwards
deque->finalprint();
break;
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY