Recursion pseudo code

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 int A(int n) {

 
	if (n == 0) {                             // Base case: if n==0, return 0
		return 0;
	}
		return max(n % 10, A(n / 10)); // Return max of current digit and 
												   // maxDigit of the rest 
	

}
int B(int n) {
	if (n< 10) {
		return n;
	}
	int d = n % 10;
	int pmin = B(n / 10);
	return (d <= pmin) ? d : pmin;
}



i saw some two recursive solution for finding the largest and the smallest digit in a number.
any idea how i write to this pseudo code .?
How can i see the algorithem in the debugger debuger in visual studio?
Hello darje,

For the pseudo code look at your code and say what should happen in simple words. Line 7 may take several lines to say what needs to be done.

How can i see the algorithem in the debugger debuger in visual studio?

Not sure what you mean here. If you want to see the source code while the program is running then put the cursor on a line and press "F9" to create a break point. Sometimes I put this std::cout << std::endl; just to use as a break point to stop the program.

When the program reaches the break point you will return to the IDE and the red dot for the break point will have a yellow arrow at the point the program stopped.

This will allow you to see your code and if you hover over a variable you will see its value.

Setting multiple break point can let you see how a variable changes.

Also while the program is in a break you can right click on a variable an add it to the watch window to see what the variable is doing.

Hope that helps,

Andy
How can i see the algorithem in the debugger debuger in visual studio?

you can't :)
algorithms are conceptual really. Shell sort is an algorithm. You can watch it sort an array in the debugger, but you can't really 'see the algorithm' because you will get lost in the details of moving a value to a variable, looking at a constant, adjusting a pointer, iterating in a loop, and whatever else is going on in there.

the best way to see an algorithm in action is to add print statements in critical areas of the code so you can see the actions of the major statements and ignore the minor housekeeping and bit shuffling under the hood that is not really the algorithm but is the 'implementation of the algorithm'. If you do it this way, you can see what it is doing better, without seeing all the required but distracting details, in other words.

In visual studio, setting careful 'watches' can be as good as print statements for seeing this but you would still have to step through all the junk. The print statements you can just run the program and look at all the information immediately to see what it did at each step. Whatever method fits your wants better, but I prefer to see just the high level actions when trying to unravel a complex routine.
Registered users can post here. Sign in or register to post.