Learning a new approach to Recursion | Rust Language
ฝัง
- เผยแพร่เมื่อ 1 มิ.ย. 2024
- Taking a new approach to learning recursion. I studied a few tutorials and videos but found that this technique from the book "Think like a programmer" helped a lot. By making an iterative solution first and the altering it to recursion using the "last part" / "last element" is quite a useful way to approach the problem.
I tried the general idea in Python first and debugged it in VScode debugger and then converted it to Rust, as you can see in this video
-- chapters --
00:00 intro
01:15 iterative version
01:59 recursive code
05:03 testing the code
Think Like A Programmer :
nostarch.com/thinklikeaprogra...
Link to article and PythonTutor example can be found here:
redandgreen.co.uk/recursion-i...
🟩 -----------------------------------------------------------------------------------------------------
Webdock Linux Hosting : webdock.io/en?maff=wdaff--170
🟩 -----------------------------------------------------------------------------------------------------
Nostr
---------
@RngWeb
findthatbit@iris.to
findthatbit.info/
redandgreen.co.uk/
#rustlang #SurrealDB #learningrust
a better issue for recursion is the memory and time overhead compared to direct code and what kinds of problems benefit form a recursive solution. "Towers of Hanoi" is a good example.
Ah, yes, that's on the list, I'll delve into that in due course. My reason for looking at recursion is to understand and use trees more👍
I thought that recursion was impossible in rust because of the ownership lol
Yeah, you do need to use a Box pointer with link lists, but (so far) recursion is ok. This example was ok as all on the stack (i32) as I understand.