![]() |
|
[C#] A small recursive utility. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] A small recursive utility. (/showthread.php?tid=1781286) |
A small recursive utility. - Ethereal - Oct 2, 2011 Earlier, I lost track of the total number of posts I had in TAFWA. For those who don't know, that's just TA's way of keeping track of helpful posts. They are stored in this format: Code (Amount) Month Day, YearI wanted to add up all of the amounts, so I wrote a quick little recursive algorithm, for a little practice, I guess. By the way, I know this isn't a beautiful algorithm, but it works and that is what matters; its an example to help people understand basic recursion. PHP Code Input: Code (15)Output: Code 33Works for anything up to: Code (99)which is enough for its use. So yeah, just a basic example. Hadn't released anything public for some time, but decided I might as well post this. * - ubbelol - Oct 2, 2011 That is some good stuff Ethereal, recursive methods is something you have to work with whether you like it or not when you get further in your programming. Here's another example I made to recursively loop through a treeviews nodes to get them all (needed this for my obfuscator project). It's kind of stupid that treeview doesn't have a property implemented to get all nodes. :l Code private List<TreeNode> RetrieveAllNodes(TreeView treeView)Probably some better way to do this? * - Nonmod - Oct 2, 2011 UbbeLol, magic answer is binary trees. Traversal alone saved up my cpu time by 40%+. Use a composite design pattern. Both combined together, produce magic of infinite amounts. * - KingCobraXD - Oct 2, 2011 Nice share. I love recursion although it can eat up a lot of memory. * - Ethereal - Oct 2, 2011 (Oct 2, 2011 05:23 AM)UbbeLoL Wrote: That is some good stuff Ethereal, recursive methods is something you have to work with whether you like it or not when you get further in your programming. (Oct 2, 2011 05:50 AM)Nonmod Wrote: UbbeLol, magic answer is binary trees. Traversal alone saved up my cpu time by 40%+. This. (Oct 2, 2011 06:59 AM)KingCobraXD Wrote: Nice share. I love recursion although it can eat up a lot of memory. Yeah, that's why you have to be careful you don't forkbomb yourself. |