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

Implement the following method as a new method for the IntNode class. (Use the u

ID: 3644950 • Letter: I

Question

Implement the following method as a new method for the IntNode class. (Use the usual IntNode definition with instance variables called data and link.)

public static boolean all42s(IntNode head)
// Precondition: head is the head reference of a linked list.
// The list might be empty or it might be non-empty.
// Postcondition: The return value is TRUE if EVERY node in the
// list contains 42 in the data part. NOTE: If the list is empty,
// then the method returns true.

Explanation / Answer

#include #include using namespace std; class Node { public: int n; Node* link; }; void display(Node* head) { coutlink!=NULL) { head=head->link; if(head->n==x) return true; } return false; } void addtail(Node*& head, int x) { if(head==NULL) { head=new Node; head->n=x; head->link=NULL; } else { Node* q=NULL; q=head; while(q->link!=NULL) q=q->link; Node* r=new Node; r->n=x; r->link=NULL; q->link=r; } } int removehead(Node*& head) { if(head==NULL) { coutn; head=NULL; return x;%0stackoverflow.com Node* p=NULL; p=head; head=head->link; x=p->n; delete p; return x; } int removetail(Node*& head) { if(head==NULL) { coutn; delete head; Node* head=NULL; return x; } Node* p=NULL; p=head; while(p->link!=NULL) p=p->link; x=p->n; delete p; return x; } int main() { int y; int z; Node* p=NULL; while(cin>>y) { addnode(p,y); } cin.clear(); cin.ignore(); cout