Question: #include #include using namespace std; struct Node { int data; Node *next; }; int countNodes(Node* head) { Node* helpPtr = head; int count = 0;

#include #include using namespace std;

struct Node { int data; Node *next; };

int countNodes(Node* head) { Node* helpPtr = head; int count = 0; while (helpPtr != NULL) { count++; helpPtr = helpPtr->next; } return count; }

void printEvenNodes(Node* head) { Node* helpPtr = head; while (helpPtr != NULL) { if (helpPtr->data % 2 == 0) { cout << helpPtr->data << ", "; } helpPtr = helpPtr->next; } }

void printAllNodes(Node* head) { Node *helpPtr = new Node(); helpPtr = head; while (helpPtr != NULL) { cout << helpPtr->data << endl; helpPtr = helpPtr->next; } }

int main(){ }

____________

Create a class and write the following methods:

  • Code for countNodes(node *head) Method:
    • The method countNodes(node *head) counts the number of nodes in the linked list and returns its to the calling main() method.
  • Code for printEvenNodes(node *head) Method:
    • The method printEvenNodes(node *head) prints all even nodes in the linked list.
  • Code for printAllNodes(node *head) Method:
    • The method printAllNodes(node *head) print all nodes in the linked list.
  • Code for Main() Method:
    • The method Main() struct the nodes in the linked list, add data to them, and link the nodes together.
    • Counts the nodes inside the linked list.
    • Print the even data from the linked list.
    • Print all data from the linked list.

Lab Activity Deliverables:

  • Just write the code as shown in the attached picture and be sure it is running: Linked List Part II.
  • Complete the class with the Main() method to make the program Run.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!