Draw Recursion Stack

[Question]: Prepare recursion stack for multilevel recursion.

func test(_ curr: Int) {
    //print("fuction-->", curr)
    if curr < 2 {
        print("first", curr)
        test(curr+1)
        print("second", curr)
        test(curr+1)
        print("Final---------> ", curr)
    }
}
test(0)
// This Prints --->
first 0
first 1
second 1
Final--------->  1
second 0
first 1
second 1
Final--------->  1
Final--------->  0

Leave a Comment

Your email address will not be published. Required fields are marked *