I would need to replace some data sequences with others, in an array, such as in this example (whose signature I imagined for the replacement function):
seq_replace(
int *array, size_t size0, // The array to modify + its size
int *to_replace, size_t size1, // The sequence to be replaced + its size
int *to_place, size_t size2); // The sequence to be placed + its size
int array[] = {0, 6, 3, 0, 6, 2};
seq_replace(
&array, 6,
(const int[]){0, 6}, 2,
(const int[]){9}, 1);
And would be obtain my array with values {9, 3, 9, 2}.
I imagine that linked lists would be more suitable for this style of task, but I work throughout my project with arrays, and making conversions between types of container would cost time.
Anyway, I don't know of any algorithm to do this kind of thing, and I haven't found anything interesting on the Internet either. I therefore turn to this site for advice on how to carry out this task.
to_placebe longer thanto_replace? If yes, what behavior is expected ? In your example, what is the result of replacing {0,6} by {7,8,9} ? Or {2} by {4,5} ?to_replaceandto_placeshould be possible. In your examples, replacing{0, 6}with{7, 8, 9}would give this:{7, 8, 9, 3, 7, 8, 9, 2}. Or replace{2}with{4, 5}would give this:{0, 6, 3, 0, 6, 4, 5}... So there is a resizing of the array, which reminds me of an implementation track, where we would not directly modify the array, but create a temporary one. I'm going to see if there's a way to do it like that.dup swapwithdup, orswap swapby<nothing>. I don't see how else to do it, actually.