Interesting interview questions 1-1 one-way linked list

Source: Internet
Author: User

It is known that there is a one-way linked list in the memory, indicating the method is 1 2 3... n

Now, only one node m is provided, and only the node m must be on this one-way linked list.

The requirement is to delete node M.

I don't know where the start point of the one-way linked list is.

 

The general idea is to find m-1, M-1 to M,

But the problem here is that this is a one-way linked list,

M cannot be found at all.

 

Therefore, we need to think differently.

The so-called delete operation can be done in another way,

If you know m, you will know m + 1 m + 2... n.

Copy the value of M + 1 to m, and point the next element of m to m + 2.

Then the M node is deleted from the content.

 

Of course, this deletion is imperfect.

The greatest difficulty for him is to broaden your thinking and not to be limited to the existing knowledge,

First try to solve the problem, and then solve the problem caused by the actual application

 

PS1: if external data points to the m + 1 address, this may cause problems.

PS2: if it is the last node, it will be over.

If you have other questions, please add

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.