include iostream include vector using namespace std struct Node int in

 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
#include <iostream>
#include <vector>
using namespace::std;
struct Node {
int index;
string value;
Node *parent;
vector<Node*> children;
};
class STree {
private:
string kurwa;
Node *root;
bool tryInsert(int index, Node *newNode) {
if (root->index == index) {
newNode->parent = root;
root->children.push_back(newNode);
return true;
} else {
for (int i = 0; i < root->children.size(); i++) {
if (root->children[i]->index != index) {
Node *result = getNode(index, root->children[i]);
if (result != 0) {
result->children.push_back(newNode);
return true;
}
delete result;
} else {
root->children[i]->children.push_back(newNode);
return true;
}
}
}
return false;
}
Node *getNode(int index, Node *&node) {
for (int i = 0; i < node->children.size(); i++) {
if (node->children[i]->index != index) {
Node *result = getNode(index, node->children[i]);
if (result != 0)
return result;
delete result;
} else {
return node->children[i];
}
}
return 0;
}
void notacjaPolska(Node *&node) {
if (node == 0)
return;
for (int i = 0; i < node->children.size(); i++)
notacjaPolska(node->children[i]);
kurwa += node->value;
}
public:
STree() {
}
void insertNode(int numOfNode, string value, int newNodeIndex) {
Node *newNode = new Node;
newNode->index = newNodeIndex;
newNode->parent = 0;
newNode->value = value;
if (root == 0){
root = newNode;
return;
}
if (!tryInsert(numOfNode, newNode)) {
newNode->parent = root;
root->children.push_back(newNode);
}
}
string notacjaPolska() {
kurwa = "";
notacjaPolska(root);
return kurwa;
}
~STree() {
delete root;
}
};