k is an index of array element so we won't nee to check if k is longer than array size. |
Yes and no.
What is
duz
?
When you create a Workflow, you set duz to something and allocate an array that has duz elements.
How many Steps are in the Workflow at that point? 0. None. You have not inserted any yet.
You insert one Step. How many steps are there now? 1
How many elements are in the array? duz, unless you reallocate.
However, in your original code you increment the duz.
You have two options:
1. Keep track of both the size of the array and the count of Steps in it. Then you do need two variables: duz and
something. That is how std::vector works.
2. The size of array is exactly the count of Steps at all times. When you create a Workflow, the duz==0 and array has no elements. Every time you insert, you must allocate larger array and copy all Steps. Every time you remove, you should shrink the array.