programming-team-code / programming_team_code_rust

rustaceans
Creative Commons Zero v1.0 Universal
2 stars 0 forks source link

Dfs closure #67

Closed lrvideckis closed 1 month ago

lrvideckis commented 1 month ago

pro: functions pre and post are called in the order they would be in a normal dfs, so random example of something you could do with this, but not with current pre-post order Vec's: keep track of DFS stack for O(1) offline kth-par

con: you can't modify the actual adjacent list var inside the closure; so this can't be used for HLD

on a side note; using unnecessary space (the Vec which stores pre,post order) kinda bugs me - this is the motivation for doing it instead with closures: also this way with closures is more functional. For the same reason, I think we should switch https://github.com/programming-team-code/programming_team_code_rust/blob/main/src/numbers/primes.rs#L53 to calling closure on each prime factor instead of returning array