-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
84 lines (78 loc) · 2.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* File: main.cpp
* Author: EvanMisshula
*
* Created on February 13, 2011, 1:36 AM
*/
#include <cstdlib>
using namespace std;
/*
*
*/
//int main(int argc, char** argv) {
int next_tree_search_bt(int level,int *list,int maxlevel,int* numposs)
{
//printf("next_tree_search: level = %d maxlevel = %d\n",level,maxlevel);
//printf(" list[level] = %d\n",list[level]);
/* */
/* If maxlevel is 0, meaning that there is only one */
/* level, then just increment the value in list */
/* until list[0] goes through all its possible */
/* values and in that case set level to -1 to */
/* indicate the end */
/* */
if(maxlevel==0)
if(list[0] < numposs[0]-1)
{
list[0]=list[0]+1;
level=0;
}
else
{
level=-1;
}
/* */
/* Number of levels is greater than 1 */
/* */
else
if(level < maxlevel)
{
/* */
/* We are not at the maximum depth */
/* go one level deeper in tree search */
/* */
level++;
list[level]=0;
}
else
{
/* */
/* We are at the maximum tree depth */
/* */
/* If there is another possible value for this */
/* level, consider it. */
/* */
if(list[level] < numposs[level]-1)list[level]++;
else
{
/* */
/* There are no more possibilities to consider for */
/* the last level in the tree search */
/* */
/* So back track to the previous level and try */
/* the next possible value there */
/* */
while (level >= 0)
{
level--;
if(level < 0)return level;
if(list[level] < numposs[level]-1)
{
list[level]=list[level]+1;
return level;
}
}
}
}
return level;
}