class node TYPEDEF typedef double value_type // CONSTRUCTOR node ( constvalue ty
ID: 3586434 • Letter: C
Question
class node TYPEDEF typedef double value_type // CONSTRUCTOR node ( constvalue type & init-data { data-field new datai ) new_link:) value-type ( - node: init link -NULL , init-data: er functions to set the data and 1ink fields: link-field -init-i ink.) - void set data (constvalue typeinew d i data field void set 1ink (node new_link) link field- // Constant member function to retrieve the current data: value-typedata( )const { 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_typedata field: node link field; 1-Implement the following function as a new function for the linked list toolkit. (Use the usual node definition with member variables called data and link.) size t count_42s (const node head_ptr) linked list. // The list might be empty or it might be non-empty. / Postcondition: The return value is the number of occurrences /I of 42 in the data field of a node on the linked list. // The list itself is unchanged.Explanation / Answer
// This is the required function
size_t count_42s(const node* head_ptr){
size_t n=0;
node* head=head_ptr;
while(head!=NULL){
if(head->data==42)
n++;
head=head->link;
}
return n;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.