Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Given the node definition: class node public: TYPEDEF typedef double value ty

ID: 3803858 • Letter: 4

Question

4. Given the node definition: class node public: TYPEDEF typedef double value type CONSTRUCTOR node( const value type& init data value type() node init link NULL data field init data; link field init link Member functions to set the data and link fields: void set data(const value type new data) data field new data void set link(node new link) f link field new link; Constant member function to retrieve the current data: value type data() const f return data field; Two slightly different member functions to retreive the current link: const node" link() const return link field; node" link() return link field; private: value type data field; node" link field; Implement the following function as a new function for the linked list toolkit. (5 points) bool has 42 (const node head ptr) i Precondition: head ptr is the head pointer of a linked list. The list might be empty or it might be non-empty Post condition: The return value is true if the list has at least one occurrence of the number 42 in the data part of a node.

Explanation / Answer

please refer the below code for the function formats

4.

program for 42 in a node

bool has_42(const node *head_ptr ) {
   //take a temp pointer
   node *temp;
   // store head pointer value in temp
   //check if its not null go ahead
   for (temp = head_ptr;temp!=NULL;temp=temp->link()) {
       if (temp->data()==42){
           //return true if its 42
           return true;
       }
       else {
       //else return false
           return false;
       }
   }
}

5. the explanation and code is as follows for the above question 5

dnode * find_data(const dnode *head_ptr,int target) {
   //take a temp pointer
   node *temp;
  
   // store head pointer value in temp
   //check if its not null go ahead
   for (temp = head_ptr;temp!=NULL;temp=temp->link()) {
       if (temp->data()== target){
       //return data for first node if the data is same as target
           return temp->data();
       }
       else {
       //else return NULL
           return null;
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote