Homework Solution: list_handout 09/08/17 09:57:11 #include #include using namespace…

    See list_handout.pdf for the class definition and implementation of a double linked list. Rewrite the findnode(int index)functionto perform a forward search in the first half ofthe list if index<N/2 and a backward search in the second half of the list otherwise. The result should be that no more than N/2 nodes will be visited as part of a search.Hint: Sketch what you are trying to accomplish on a piece of paper before you thinkabout the code. list_handout 09/08/17 09:57:11 #include <iomanip> #include <iostream> using namespace std; Hint: Notice how the three different list implementations on the next several pages use the SAME public interface with the only differences being wrt the implementation details class 1ist/see next several pages Hint: Notice how the operator member functions are overloaded differently to support the different underlying 1ist types void printlist (const char operation, list &v) cout < setw (14)< operation << s= << v.size ( ) Hint: The array based list is similar to the std: :vector class The single and double linked lists mimic the std: list class We will make a few more improvements to make the similarities even more striking soon. See cplusplus.com for details on the two std container classes mentioned for (int i-0 i<v.size); i++) cout << cout <<n; int main(int argc, char argv) Hint: For HW2, you will implement single linked list class member functions push_front , pop front) and front). For HW3, you will implement an improved findnode ) member function for the double linked 1ist class cout << left; printlist (list v, v) list v; v.push back (7) printlist(v.push back (7), v) v.push back (8)printlist(v.push_back (8), v)i v.push_back (9)printlist (v.push_back (9), v) v.insert (1, 20) printlist (v.insert (1,20) , v v.erase (2) v.insert (0, 11) printlist (v.insert (0,11), v) v.push_back (2)printlist (push_back (2) , v)i v.pop back ) v.insert (1, 4) printlist (v.insert (1,4), v) Hint: The single and double linked list classes share the implementation of many member functi ns. These are defined in the former and referred to by in the latter to save space printlist (v.erase (2) , v) printlist (pop_back ), v)i Hint: If you cant wrap your head around the code, draw a simple picture similar to those drawn in class. print list (v[1] = 5, v); printlist (clear, v)i v.clear i unix> ./list list v v.push-back (7) s=1 : 7 v.push_back (8) s-2 7 8 ˇ·push-back (9) s=3 : 7 8 9 v.insert (1,20) : 7 20 8 9 v.erase (2) v.insert (0,11) -4:11 7 20 9 push back (2) 5 11 7 20 9 2 pop back ) v.insert (1, 4) S-511 47 20 9 v[1] = 5 clear ( s=0 : s-37 20 9 s-4:11 7 20 9 s=5 : 11 5720 9 S=0
    list_handout 09/08/17 09:57:11 #include #include using namespace std; Hint: Notice how the three different list implementations on the next several pages use the SAME public interface with the only differences being wrt the implementation details class 1ist/see next several pages Hint: Notice how the operator member functions are overloaded differently to support the different underlying 1ist types void printlist (const char operation, list &v) cout

    Expert Answer

     
    node *findnode(int n){ node *p;

    See roll_handout.pdf coercion the arrange limitation and toolation of a inclose linked roll. Rewrite the findnode(int protest)functionto discharge a impertinent quest in the chief half ofthe roll if protest<N/2 and a awkward quest in the assist half of the roll incorrectly. The effect should be that no over than N/2 nodes achieve be visited as segregate of a quest.Hint: Sketch what you are troublesome to achieve on a constituent of paper antecedently you thinkabout the sequence.

    list_handout 09/08/17 09:57:11 #include <iomanip> #include <iostream> using namedistance std; Hint: Notice how the three irrelative roll toolations on the contiguous distinct pages correction the SAME general interface with the merely differences life wrt the toolation details arrange 1ist/see contiguous distinct pages Hint: Notice how the operator part offices are overloaded irrelatively to food the irrelative underlying 1ist types wanting imprintroll (const char performance, roll &v) cout < setw (14)< performance << s= << v.bigness ( ) Hint: The pull-up based roll is concordant to the std: :vector arrange The one and inclose linked rolls imitate the std: roll arrange We achieve effect a sconfused-talk over improvements to effect the concordantities uniform over surprising shortly. See cplusplus.com coercion details on the span std container arrangees mentioned coercion (int i-0 i<v.size); i++) cout << cout <<n; int ocean(int argc, char argv) Hint: Coercion HW2, you achieve tool one linked roll arrange part offices press-against_face , explode face) and face). Coercion HW3, you achieve tool an improved findnode ) part office coercion the inclose linked 1ist arrange cout << left; imprintroll (roll v, v) roll v; v.press-against tail (7) imprintlist(v.press-against tail (7), v) v.press-against tail (8)printlist(v.push_tail (8), v)i v.push_tail (9)printroll (v.push_tail (9), v) v.inoculate (1, 20) imprintroll (v.inoculate (1,20) , v v.obliterate (2) v.inoculate (0, 11) imprintroll (v.inoculate (0,11), v) v.push_tail (2)printroll (push_tail (2) , v)i v.explode tail ) v.inoculate (1, 4) imprintroll (v.inoculate (1,4), v) Hint: The one and inclose linked roll arrangees distribute the toolation of abundant part functi ns. These are defined in the coercionmer and referred to by in the departure to preserve distance imprintroll (v.obliterate (2) , v) imprintroll (pop_tail ), v)i Hint: If you confused-talk cover your mind about the sequence, pull a sincere paint concordant to those pulln in arrange. imimprint roll (v[1] = 5, v); imprintroll (clear, v)i v.obvious i unix> ./roll roll v v.push-tail (7) s=1 : 7 v.push_tail (8) s-2 7 8 ˇ·push-tail (9) s=3 : 7 8 9 v.inoculate (1,20) : 7 20 8 9 v.obliterate (2) v.inoculate (0,11) -4:11 7 20 9 press-against tail (2) 5 11 7 20 9 2 explode tail ) v.inoculate (1, 4) S-511 47 20 9 v[1] = 5 obvious ( s=0 : s-37 20 9 s-4:11 7 20 9 s=5 : 11 5720 9 S=0

    list_handout 09/08/17 09:57:11 #include #include using namedistance std; Hint: Notice how the three irrelative roll toolations on the contiguous distinct pages correction the SAME general interface with the merely differences life wrt the toolation details arrange 1ist/see contiguous distinct pages Hint: Notice how the operator part offices are overloaded irrelatively to food the irrelative underlying 1ist types wanting imprintroll (const char performance, roll &v) cout

    Expert Vindication

     

    node *findnode(int n){
    node *p;
    int compute,found;
    compute = 0;
    fix = 0;
    if (mind == NULL)
    return NULL;
    p = mind;
    count
    if (n < N/2) {
    while (compute <= N/2){
    if (p->data == n){
    fix = 1;
    break;
    }
    p = p->next;
    count++;
    }
    }
    else{
    while (p->contiguous != NULL)
    p = p->next;
    while (compute <= N/2){
    if (p->data == n){
    fix = 1;
    break;
    }
    p = p->prev;
    count++;
    }
    }
    if (fix == 1)
    return p;
    else
    return NULL;

    }