Comment

Comment by hatthew

What's the utility of this? It's arguably still using a stack, just encoded in the original data structure itself. If your original data structure somehow uses colors but is also fine with the algorithm overwriting with its own colors, I guess it works? But those are very unusual preconditions. For any real world scenario I can imagine, I feel like there's a better solution.

If the colors in your original data are important, then you can't really just overwrite them and/or assume that the algorithm can use its own colors. You're going to have to add a stack.

If your original data doesn't have colors, adding a stack is better than integrating metadata into the original data structure.

If for some reason your original data has colors but they aren't considered important, then just remove the colors and add a stack.

If your concern is about dynamic memory, preallocate static memory equal to the size of the original data structure.

parent hatthew 4 days ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton