Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

c++ - How to get whatever data in previous and next pointer of a singly linked list


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...