-
Notifications
You must be signed in to change notification settings - Fork 0
/
Branch.cpp
executable file
·110 lines (106 loc) · 1.99 KB
/
Branch.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
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
#include "Header.h"
void List::push(char** b, int m)
{
Element *pver;
Element *pdown;
int a = b[1][m - 1] - 48;
for (int i = m - 1; i >= 0; i--)
{
if (Ver != 0)
{
a += b[1][i] - 48;
pver = new Element(1, a);
pdown = new Element(0, b[0][i]);
Ver->previous = pver;
pver->straight = Ver;
pdown->previous = pver;
pver->down = pdown;
Ver = pver;
}
else
{
pver = new Element(1, b[0][i]);
Ver = pver;
Ver->straight = 0;
Ver->down = 0;
}
}
}
void List::Kodir(List a, char * mas, char *mas1, int &t)
{
Element * ptr = a.Ver;
int data1;
t = 0;
for (int i = 0; i < strlen(mas1); i++)
{
ptr = a.Ver;
while (ptr->straight != 0)
{
if (ptr->down->symb != mas1[i] && ptr->straight->symb != mas1[i])
ptr = ptr->straight;
else
{
if (ptr->down->symb == mas1[i])
data1 = ptr->down->data;
else
data1 = ptr->straight->data;
ptr = ptr->down;
while (ptr->previous->previous != 0)
{
mas[t] = ptr->previous->data + 48;
t++;
ptr = ptr->previous;
}
mas[t] = data1 + 48;
t++;
break;
}
}
}
}
void List::Dekor(char* mas, List a, char*str, int len)
{
Element*ptr = a.Ver;
int t = 0;
for (int i = 0; i < len; i++)
{
if (0 == mas[i] - 48)
ptr = ptr->down;
else
ptr = ptr->straight;
if (ptr->straight == 0)
{
str[t] = ptr->symb;
t++;
ptr = a.Ver;
}
}
str[t] = '\0';
}
ostream & operator << (ostream&s, List &a)
{
Element *ptr = a.Ver, *ptrsave = ptr;
int data;
char symb;
while (ptrsave->straight != 0)
{
ptr = ptrsave->down;
data = ptr->data;
symb = ptr->symb;
while (ptr->previous->previous != 0)
{
ptr = ptr->previous;
s << ptr->data;
}
s << data << " - " << symb << endl;
ptrsave = ptrsave->straight;
}
ptr = ptrsave;
while (ptr->previous != 0)
{
s << ptr->data;
ptr = ptr->previous;
}
s << " - " << ptrsave->symb << endl;
return s;
}