# Thread: Binary trees

1. ## Binary trees

Hello, I just got this assignment on binary trees, its just tracing through and seeing what numbers i end up with. I dont know how to read this and get the acctual answers. I can put it into visual studio and get it but would it be possible for any of you to explain to me of how this program specificly works?? thanks
Code:
```   1. Consider the program:

#include <iostream>
using namespace std;

void p(int x)
{
if (x < 0) return;
p(x-1);
cout << x << endl;
p(x-2);
}

main()
{
int y;
while (cin >> y, y >= 0) {
p(y);
cout << "*************" << endl;
}
}

Trace the program by hand to get the output of p(0), p(1), p(2), p(3) and p(4).

2. Conisder the program:

#include <iostream>
using namespace std;

void p(char A[], int m, int n)
{
if (m == n) {
for (int i = 0; i < n; i++) cout << A[i];
cout << endl;
return;
}
for (char c = 'A'; c <= 'C'; c++) {
A[m] = c;
p(A,m+1,n);
}
}

main()
{
char B[10];
int k;
cin >> k;
p(B,0,k);
}

Trace this program by hand and determine for nonnegative integer k, what is the output of p(B,0,k).```

2. I don't have the knowledge to explain, but here are some really great explanations:
http://www.eternallyconfuzzled.com/t..._tut_bst1.aspx

Popular pages Recent additions