C++ Programming Activity: Deque Linked List Explain the flow of the main code not necessarily every line
C++ Programming Activity: Deque Linked List Explain the flow of the main code not necessarily every line
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
C++ Programming
Activity: Deque Linked List
Explain the flow of the main code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow.
SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS
int main(int argc, char** argv) {
DLLDeque* deque = new DLLDeque();
int test;
cin >> test;
//Declarations
int tempnum;
int num;
int sum;
int count;
bool addfirst = false;
bool addlast = false;
bool remfirst = false;
bool remlast = false;
switch (test) {
case 0:
//Implementation
do{
cin >> num;
if(num == 0){
break;
}
//Reset
tempnum = num;
count = 0;
sum = 0;
addfirst = false;
addlast = false;
remfirst = false;
remlast = false;
//Sum of Digits
while(tempnum != 0){
sum += tempnum % 10;
tempnum /= 10;
}
//Rules
if(sum % 2 == 0) {
addfirst = true;
count++;
}
if(sum % 3 == 0) {
remfirst = true;
addlast = true;
count++;
}
if(sum % 5 == 0 && count < 2) {
remlast = true;
if(addfirst == false){
addfirst = true;
}
if(addlast == false){
addlast = true;
}
count++;
}
if(sum % 7 == 0 && count < 2) {
if(remfirst == false){
remfirst = true;
}
if(remlast == false){
remlast = true;
}
if(addfirst == false){
addfirst = true;
}
count++;
}
if(count == 0) {
deque->addLast(num);
}
if(remfirst == true){
deque->removeFirst();
}
if(remlast == true){
deque->removeLast();
}
if(addfirst == true){
deque->addFirst(num);
}
if(addlast == true){
deque->addLast(num);
}
}
while(num != 0);
deque->final_print();
break;
![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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6a8dd343-05d5-4c47-959b-e09f7e32f213%2F9f138a14-0387-492a-a2ad-3cce41d6ce12%2F02m3h2f_processed.png&w=3840&q=75)
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.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY