Question: c++ Define the SLL member function int speciaDecrement(int v), which finds the last node whose value is a multiple of 5 and replaces the value
c++
Define the SLL member function int speciaDecrement(int v), which finds the last node whose value is a multiple of 5 and replaces the value in the node before it with v. If no value in the list is a multiple of 5, or if the only multiple of 5 is value is in the first node, then the function does no decrement and returns -77. For example, if the list was [15, 24, 9, 30, 11], then after executing speciaDecrement( 4), it will become [15, 24,5,30,11), and the function returns 9. Also, if the list was [20,7,54,17], then after executing speciaDecrement( 4), the list remains [20,7,54,17] and the function returns -77. Below is the SLL API you are allowed to use to solve this question: class SLLE private: Node h;//stores the address of the first cell in the list Node* t;//stores the address of the last cell in the list public: //constructors SLL(); SLL(); //Get Information bool isEmpty();//the list is empty iff both head and tail are equal to null void print();/eeds a loop from head to tail that prints all info inbetween int getHead();//retruns the address of the first node in the list int getTail();//returns the address of the last node in the list Node* getHeadNode();//returns the address of the first node in the list Node* getTailNode();//returns the address of the last node in the list }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
