Vectors/Parity

Apr 2, 2016 at 7:40am
Hey! Can anyone help me with the following: how to make a function which from vector of integers finds and removes all numbers whose digits are of the same "parity" (eg. 351, 246) but without the usage of helping vectors, arrays and without the use of function("erase") or functions from "algorithm" bibl.?
Thanks :)
Apr 2, 2016 at 11:08am
Go through the vector. At each element, if the digits are of the same parity, copy everything following in the vector one element to the left. This overwrites the element you want eliminated.

Keep track of how many you overwrite. When finished, resize the vector to (original_size - number_overwritten). Done, without having used "erase", any algorithms or any more vectors.
Last edited on Apr 2, 2016 at 11:09am
Topic archived. No new replies allowed.