public static BinTree Parse(string str) { BinTree tree = new BinTree(); string substring; int counter = 0, counterOfBrackets = 0; bool isDecimalSeparator; for (int i = 0; i < str.Length; i++) { isDecimalSeparator = false; if (str[i] == '(') { counter = 0; counterOfBrackets++; while (counterOfBrackets > 0) { i++; if (i >= str.Length) { break; } if (str[i] == ')') { counterOfBrackets--; } else if (str[i] == '(') { counterOfBrackets++; } counter++; } //i--; substring = str.Substring(i - counter + 1, counter - 1); BinTree tmpTree = Parse(substring); tree.AddToTree(tmpTree.Root, true, 1); //i += 2; continue; } if (digits.Contains(str[i])) { counter = 0; while (digits.Contains(str[i])) { counter++; i++; if (i >= str.Length) { break; } } substring = str.Substring(i - counter, counter); if (substring.Contains(decimalSeparator)) { isDecimalSeparator = true; } tree.AddToTree(WhatTypeOfObject(substring, isDecimalSeparator)); i -= 1; continue; } if (acts.Contains(str[i])) { counter = 0; while (!digits.Contains(str[i])) { counter++; i++; if (str[i] == '(' | str[i] == ')') { break; } } substring = str.Substring(i - counter, counter); tree.AddToTree(WhatTypeOfObject(substring, isDecimalSeparator), false); i--; continue; } } return tree; }
public void Copy(BinTree <T> tree2) { copy(ref root, tree2.root); }