It is not possible to get previous data in constant time in a singly linked list unless you are saving previous value since beginning in a variable.
You can only move forward(not back) in Singly linked list. So you have two options either get the previous data using a loop or to save it in a variable when you are traversing through the linked list.
Also the next pointer in this new node will be a null pointer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…