About array false negative

Source: Internet
Author: User

Determines all elements within the array and removes the element that satisfies the condition.

Eg: We need to delete an array of more than 3 elements in arr, then we write the following code:

The execution results of this code are as follows

,

It will be found that the content does not match the expected result of the false negative caused by the pointer to the relative position of the element.

Make the following modifications to the code (add a line i--;)

i--is added, and then it is the result we need.

i--; What you do is change the position of the pointer and make a judgment on each element.

Once the content position changes, the pointer position should also change accordingly, so you can avoid false negative.

You can find the i--in the code written by the teacher today; After commenting out, the code runs on the naked eye without any difference, because the timer executes once every 10ms, so the For loop inside is also 10ms executed once, then the false negative object, will be deleted the next time the For loop is executed, but it all happens too quickly, so the naked eye doesn't make a difference.

This article is based on today's teacher's judgment boundary of the For loop, everyone to i--, the understanding of the problem written, personal opinion, for reference only.

About array false negative

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.