Subject Computer Science C-Family Programming

Question

1. Write a function that steps through a linked list of nodes with integer values, changing every other item to zero.
The function’s parameter should be a pointer to a node, and it should have a local variable that is a node iterator.

2. Write a function that steps through a linked list of nodes with integer values, counting the number of occurrences of zero.
The function’s parameter should be a pointer to a const node, and it should have a local variable that is a const_node_iterator.
Test both the functions in main()
You can use node2.h and node2.template file

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

int main(int argc, char** argv) {
    node<int> * n = NULL;
   
    for (int i = 0; i < 5; i++) {
       n = new node<int>(i, n);
    }
   
    cout << "Current list: ";
    Print(n);   
    cout << "\nNumber of occurrences of zero: " << ZeroCounting(n) << "\n";
    cout << "\n";
   
    cout << "Changing every other item to zero\n";
    ZeroOut(n);   
    cout << "Current list: ";
    Print(n);   
    cout << "\nNumber of occurrences of zero: " << ZeroCounting(n) << "\n";
   
    return 0;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$23.00

or $1 if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats