-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
178 lines (151 loc) · 3.8 KB
/
main.cpp
File metadata and controls
178 lines (151 loc) · 3.8 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Sergeev Artemiy, 33601/2 (3057/2) */
#include <stdio.h>
#include <conio.h>
#include <vector>
#include "tree_gen.h"
/* Debug memory check support */
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
# include <crtdbg.h>
# define SetDbgMemHooks() \
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF | \
_CRTDBG_ALLOC_MEM_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
#else
#define SetDbgMemHooks() 0
#endif /* _DEBUG */
/* Disable some 'idiots' (in my opinion) warnings about printf and scanf */
#pragma warning(disable:4996)
#define SIZE_X 20
#define SIZE_Y 10
#define MAX_TREE_STR 7
char treeTable[SIZE_X][SIZE_Y][MAX_TREE_STR] = {0};
/* Recursive function for print tree function */
unsigned int makeTreeTable( tree_layout &layout, unsigned int index, int &x, int y )
{
unsigned int i = index + 1;
unsigned int numOfChildrens = 0;
if (index < layout.size())
{
if (layout[index + 1] - 1 == layout[index])
i = makeTreeTable(layout, index + 1, x, y + 1);
sprintf(treeTable[x][y], "%i ", index);
x++;
while (layout[index] + 1 == layout[i])
i = makeTreeTable(layout, i, x, y + 1);
}
return i;
}
/* Simple print tree by layout function */
void printTree( tree_layout &layout )
{
int i, j, x = 0;
if (layout.leftHeight() + 1 > SIZE_Y || layout.size() - 1 > SIZE_X)
printf("Tree is very big for print\n");
/* Erase tree table for output */
for (i = 0; i < SIZE_X; i++)
for (j = 0; j < SIZE_Y; j++)
sprintf(treeTable[i][j], " ");
makeTreeTable(layout, 0, x, 0);
/* Print tree table to screen */
for (j = 0; j < SIZE_Y; j++)
{
for (i = 0; i < SIZE_X; i++)
printf(treeTable[i][j]);
printf("\n");
}
}
/* Print one tree layout */
void printLayout( tree_layout &layout )
{
printf("[0");
for (unsigned int i = 1; i < layout.size(); i++)
printf(" %u", layout[i]);
printf("]\n");
}
/* Get free non-isomorphyc trees count function */
unsigned int getTreesCount( unsigned int vertexCount )
{
unsigned int count = 1;
tree_layout layout(vertexCount);
while (!layout.isSimple())
{
count++;
layout = tree_generator::buildLayout(layout);
}
return count;
}
unsigned int printLayouts( unsigned int vertexCount )
{
unsigned int count = 1;
tree_layout layout(vertexCount);
while (!layout.isSimple())
{
printf("%2i -> ", count++);
printLayout(layout);
layout = tree_generator::buildLayout(layout);
}
printf("%2i -> ", count);
printLayout(layout);
return count;
}
unsigned int printTreesAdv( unsigned int vertexCount )
{
unsigned int count = 1;
tree_layout layout(vertexCount);
while (!layout.isSimple())
{
printTree(layout);
layout = tree_generator::buildLayout(layout);
}
printTree(layout);
return count;
}
void printTreesCount( unsigned int vertexNum )
{
printf("%3u -> %u", 0, 0);
for (unsigned int i = 1; i <= vertexNum; i++)
printf("\n%3u -> %u", i, getTreesCount(i));
}
void printMenu( void )
{
printf("\n0 - Exit\n"
"1 - Print trees\n"
"2 - Print trees count\n"
"3 - Advanced print trees\n"
"Your choise is: ");
}
int main( void )
{
SetDbgMemHooks();
bool run = true;
unsigned int choice = 0;
unsigned int vertexNum;
while (run)
{
printMenu();
scanf("%u", &choice);
switch(choice)
{
case 0:
run = 0;
break;
case 1:
printf("\nPrint number of vertices: ");
scanf("%u", &vertexNum);
printLayouts(vertexNum);
break;
case 2:
printf("\nPrint maximum vertices number: ");
scanf("%u", &vertexNum);
printTreesCount(vertexNum);
break;
case 3:
printf("\nPrint number of vertices: ");
scanf("%u", &vertexNum);
printTreesAdv(vertexNum);
break;
}
}
return 0;
}