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...
icon
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY