Why is deleting in a single linked list O(1)?

后端 未结 8 2497
悲哀的现实
悲哀的现实 2020-12-25 14:50

I do not quiet understand why deleting at the end of a single linked list goes in O(1) time, as the wikipedia article says.

A single linked list consists out of node

8条回答
  •  情书的邮戳
    2020-12-25 15:19

    For example, you can have a pointer to the element before last ("second from end") and when deleting: 1. Delete *next of this "second from end" element. 2. Set this "second from end" *next to NULL

提交回复
热议问题