MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / initTree

Function initTree

CPP/Trees/Expression_tree/BST.c:115–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115void initTree(EXT *tree, char* inputString, int size) {
116 inputString = convertToPostFix(inputString, size);
117
118 int index = 0;
119 StackList stack;
120 initStack(&stack);
121 while(inputString[index] != '\0') {
122 if(!is_operator(inputString[index])) {
123 push(&stack, (void *) createEXTNode(inputString[index], NULL, NULL));
124 } else {
125 Node* element2 = (Node *)peek(stack);
126 pop(&stack);
127
128 Node* element1 = (Node *)peek(stack);
129 pop(&stack);
130
131 push(&stack, (Node *)createEXTNode(inputString[index], element1, element2));
132 }
133 index++;
134 }
135
136 Node* finalTree = (Node *) peek(stack);
137 pop(&stack);
138
139 *tree = finalTree;
140
141}
142
143void traverse(EXT tree) {
144 if(tree != NULL) {

Callers 1

mainFunction · 0.85

Calls 7

convertToPostFixFunction · 0.85
initStackFunction · 0.85
is_operatorFunction · 0.85
createEXTNodeFunction · 0.85
pushFunction · 0.70
peekFunction · 0.70
popFunction · 0.70

Tested by

no test coverage detected