I'm getting an error for the bold face code. Does there any solution so that while traversing through the list in a loop we can take a previous iterator like the code above, instead of creating a temp iterator as follows.
STL lists only offer bidirectional iterators, not random access iterators. A deque or a vector would let you do that but I would expect that you already chose to use a list for a reason.
Just throw the last iterator in a variable each time threw the loop, you don't have to explicitly back up one every time, then.