+ 3
The function declares two pointers: `temp` is used to step through each node in the list, and `temp2` is used to remember the node with the largest associated value. It then iterates over the list and updates `temp2` if the current node is bigger than the maximum so far. Afterwards, the node needs to be deleted. If it is the head of the list, a different, undeclared function is used, otherwise we find the node previous to the maximum node, connect it to the node after the maximum node instead, and delete the maximum node. Here is a commented version of the function: https://code.sololearn.com/cnaXNDBYUAK1/?ref=app
17th Feb 2022, 5:10 PM
Shadow
Shadow - avatar
0
Because you want access to the node previous to the one you are actually going to delete. By comparing the data directly to your iterator's data, you would only stop once the iterator points to the same node you are going to delete, not the previous one.
18th Feb 2022, 6:59 PM
Shadow
Shadow - avatar