Confused as to how I could implement a sorting algorithm in Processing

Definitely follow the chain of previous discussion links back from quark’s link – including to several places in the old forum.

Many / most sorting algorithms are not designed to be animated – certainly not to be reversable / rewound. If all you want is animation, then you can refactor the algorithm loop(s) to an object or set of global variables with draw “inside” it. If you need rewind as well as animation, however, sorting algorithms are NOT reversible – so a history data structure of the kind quark demonstrates is also necessary.

There is one workaround for not keeping history – although it is low performance. For deterministic sorting algorithms, you can simply pass the step number, and have it sort up to that step. So, at step 15, you could “step back” by rerunning the whole step from step 1-14. Then you don’t need a stack, you only need to save the initial non-sorted state. If the sorting algorithm involves randomness then this also requires that you save and reset from the randomSeed.