Explain the flow of the code. See attached photo for the problem. (This is not graded)  int skip(int n, int start_pos, int end_pos) {             node* currnode = head;             node* prevnode = NULL;             int delpos = 0;             int count = 0;             int pos = start_pos;             while (currnode != NULL) {                 count++;                 if (pos > end_pos){                     return delpos;                 }                 if (count == pos){                    delpos++;                     if (prevnode == NULL){                         currnode = currnode->next;                         removeHead();                         head = currnode;                     } else{                         prevnode->next = currnode->next;                         if (currnode == tail) {                             tail = prevnode;                         }                         node* rem = currnode;                         currnode = currnode->next;                         free(rem);                     }                     index--;                     pos += n;                 } else {                     prevnode = currnode;                     currnode = currnode->next;                  }             }             return delpos;         }         int remove_redundant() {             if(head == NULL && tail == NULL)             {                 return 0;             }             node* contrast = head;             node* same = NULL;             node* currnode = contrast->next;             node* prevnode = NULL;             bool add = false;             int count = 0;             while (true)              {                 if (currnode->element == contrast->element) {                     add = true;                     if (prevnode != NULL) {                         prevnode->next = currnode->next;                         if (currnode == tail) {                             tail = prevnode;                         }                         free(currnode);                         currnode = prevnode->next;                         index--;                     }                     else{                         removeHead();                         currnode = head;                     }                 }                 else{                     prevnode = currnode;                     currnode = currnode->next;                 }                 if(add == true)                 {                     count++;                     add = false;                 }                 if(currnode == NULL)                 {                     contrast = contrast->next;                     if(contrast == tail)                     {                         break;                     }                     same = contrast;                     currnode = same->next;                 }             }             return count;         }

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

Explain the flow of the code. See attached photo for the problem. (This is not graded)

 int skip(int n, int start_pos, int end_pos) {
            node* currnode = head;
            node* prevnode = NULL;
            int delpos = 0;
            int count = 0;
            int pos = start_pos;
            while (currnode != NULL) {
                count++;
                if (pos > end_pos){
                    return delpos;
                }
                if (count == pos){
                   delpos++;
                    if (prevnode == NULL){
                        currnode = currnode->next;
                        removeHead();
                        head = currnode;
                    } else{
                        prevnode->next = currnode->next;
                        if (currnode == tail) {
                            tail = prevnode;
                        }
                        node* rem = currnode;
                        currnode = currnode->next;
                        free(rem);
                    }
                    index--;
                    pos += n;
                } else {
                    prevnode = currnode;
                    currnode = currnode->next; 
                }
            }
            return delpos;
        }

        int remove_redundant() {
            if(head == NULL && tail == NULL)
            {
                return 0;
            }
            node* contrast = head;
            node* same = NULL;
            node* currnode = contrast->next;
            node* prevnode = NULL;
            bool add = false;
            int count = 0;
            while (true) 
            {
                if (currnode->element == contrast->element) {
                    add = true;
                    if (prevnode != NULL) {
                        prevnode->next = currnode->next;
                        if (currnode == tail) {
                            tail = prevnode;
                        }
                        free(currnode);
                        currnode = prevnode->next;
                        index--;
                    }
                    else{
                        removeHead();
                        currnode = head;
                    }
                }
                else{
                    prevnode = currnode;
                    currnode = currnode->next;
                }
                if(add == true)
                {
                    count++;
                    add = false;
                }
                if(currnode == NULL)
                {
                    contrast = contrast->next;
                    if(contrast == tail)
                    {
                        break;
                    }
                    same = contrast;
                    currnode = same->next;
                }
            }
            return count;
        }
• skip(int n, int start_pos, int end_pos)
This method deletes every n items in the linked list starting
from the start_pos (will be deleted first) until the end_pos. You
cannot call other methods that employ loops in this function
as it will be counterintuitive to the performance of the linked
list. For example, in the linked list 10 → 30 → 40 → 50 → 60 →
80 → 90 → 110→ 150 → 160 → 17o, having the method skip(2,
3, 10) will keep everything before the third position and after
the tenth position. The first that will be deleted is the third
position then plus n which is 2, followed by the fifth, then the
seventh, and lastly the ninth. After which, the linked list would
look like this 10 → 30 → 50 → 80→ 110→ 160 → 170
• remove_redundant()
This method will clear out the duplicate numbers in your linked
list. It is also imperative that you will use an instance of this
Linked List class to hold the numbers that you have already
checked and use the methods in this instance. In the example
10 → 10 → 20 → 30 → 10, calling remove_redundant() will
remove the other 2 10's that occurred later, hereby making the
list 10 → 20 → 30. Limitation: You cannot have a nested lop
here nor use methods that employ loops as the performance
of our linked list will suffer.
Transcribed Image Text:• skip(int n, int start_pos, int end_pos) This method deletes every n items in the linked list starting from the start_pos (will be deleted first) until the end_pos. You cannot call other methods that employ loops in this function as it will be counterintuitive to the performance of the linked list. For example, in the linked list 10 → 30 → 40 → 50 → 60 → 80 → 90 → 110→ 150 → 160 → 17o, having the method skip(2, 3, 10) will keep everything before the third position and after the tenth position. The first that will be deleted is the third position then plus n which is 2, followed by the fifth, then the seventh, and lastly the ninth. After which, the linked list would look like this 10 → 30 → 50 → 80→ 110→ 160 → 170 • remove_redundant() This method will clear out the duplicate numbers in your linked list. It is also imperative that you will use an instance of this Linked List class to hold the numbers that you have already checked and use the methods in this instance. In the example 10 → 10 → 20 → 30 → 10, calling remove_redundant() will remove the other 2 10's that occurred later, hereby making the list 10 → 20 → 30. Limitation: You cannot have a nested lop here nor use methods that employ loops as the performance of our linked list will suffer.
Expert Solution
steps

Step by step

Solved in 5 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