Hi, I need to implement: delete the nodes that contain even values from a singly linked list pointed to by head.
I have some idea of it but, got stuck during implementation: I know that bool variable to find even value has been declared but how do I put it in my code, should I use like n%2==0 then delete how should I put it?
Can you post the code with which you have a problem? Essentially what you'd have to do is something like:
if (n % 2 == 0) {
delete node; //how to actually delete the node depends on how your list is implemented
}
In a single list you will probably have a pointer used to point to the element before the one you are currently checking the value of, so if you have elements A, B and C with the values 25, 26 and 30, you'd have a pointer on A in the beginning and check A. If A is uneven, which it is, you check the next element, B, but let your pointer stay on A. If B is even, which it is, then you can delete B and set the pointer of element A which used to point to B to C. If B would have had an uneven value you would set your search pointer on B and check C next, and so on till you reach the end of the list.
It would really help to see how your list is implemented, please post your code. Unless what I wrote already answers your question.