could someone help me finding a way to do the following:
if I have a pattern like 0100101000
I want the out put like 00100010000
its like the second container always ones the consecutive position after a one is detectd in the first, but if a zero is trapped in between 2 ones like 101 it becomes 010
Re-explain the pattern? I only understood that you want to replace all instances of 101 with 010, but there's another aspect to it since there's an extra 0 at the front.
its like the second container always ones the consecutive position after a one is detectd in the first
I assume this explains that first pattern the output is supposed to follow, but I have no idea what you're trying to say.
You can indeed do something like that ... but it is like scanning all 365 days in a year when only one is your birthday. In other words, highly inefficient. Imagine if your vector was 1 million items long. You can check 2 million items or you can check a million million items - entirely your choice, but I know which I would do.
The purpose of the if tests is simply to go directly to placing the '1', but making sure that I didn't go beyond the end of the array/string.