I’ve my unique program of this utilizing the idea of stacks nonetheless, I discover it troublesome on updating the weather of the array. As an alternative of utilizing the identical idea, I’ve modified it and made it simply to a static array with mounted parts.
I hope this program/idea may assist in your actions/projects.