```
What you are checking is:
Starting with the second point:
p[i+1] >= p[i]-10 && p[i+1] <= && p[i]+10
That is, the next point must be in a range of +-10 of the point before.
If this is true, p[i+1] is not an error.
The problem is clear with the first point being the real error.
A solution would be:
Starting with the first point:
Check for
p[i+1]+10 > p[i] && p[i+1]-10 < p[i]
In this case the check logic is something else. Imagin the second point in the middle of the range:
i o
i+1 |--------o--------|
From the left to right every position is allowed.
If the position is the most left one which is p[i]-10 = p[i+1]
than p[i] not to be an error
p[i] < p[i+1]+10 must be true.
And if the position is the most right one which is p[i]+10 = p[i+1]
than p[i] not to be an error
p[i] > p[i+1]-10 must be true.
All together:
p[i] is not an error if
p[i+1]+10 > p[i] && p[i+1]-10 < p[i]
is true.
But thats still not all, because now the second last point can be an error, but the real error is the
last one. A new problem.
Solution:
For all points except the first one and the last one, check both conditions:
1 is the index of the first point, m is the index of the last point, k is the current point to check:
for 1<k<m
conditions:
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
or
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
must be true, for p[k] not to be an error.
for k=1 (the first point):
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
must be true, for p[k] not to be an error.
for k=m (the last point):
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
must be true, for p[k] not to be an error.
Implementing it now should be straight forward.
There is still a problem: say some point in the middle is an error in comparison
to the points before but not in comparison to the points after it. Which means you
have to lists where all points would be ok if the two lists would be separated.
Checking like described will not find an error. But this condition is not defined
in your explanation. Its an undefined condition of the list of points in your
scenario. Add another condition, called "break of lists" = b.
p[k] is of type b, if
( p[k] <= p[k-1]+10 and p[k] >= p[k-1]-10 )
XOR
( p[k] < p[k+1]+10 and p[k] > p[k+1]-10 )
is true.
Regards,
Oli
PS: long explanation but I developed it during writing :-)
Short version: check in both directions for each points, for the first point check against next one only, for the last point check against the second last only. Scenarion "break of list" maybe unpossible in your case or use the XOR rule to find out.
```