private static int REPLACEONE(string str, bool isConsole) { SimpleRope a = Stack.Get(1); SimpleRope b = Stack.Get(2); SimpleRope c = Stack.Get(3); SimpleRope ret = Stack.Get(4); Regex regex = new Regex(b.ToString()); bool isPossible = regex.Match(a.ToString()).Value.Any(); if (!isPossible) { Stack.Pop(4); Stack.Push(a); var idx = MyField.LabelDict[ret.ToString()]; return(idx); } else { string newstr = regex.Replace(a.ToString(), c.ToString(), 1); Stack.Pop(4); var strRp = new SimpleRope(newstr, null, null); Stack.Push(strRp); return(MyField.CurrentExecuteLine + 1); } }
public SimpleRope(string str, SimpleRope left, SimpleRope right) { this.str = str; this.left = left; this.right = right; this.height = 1; }
public static SimpleRope balance(SimpleRope p) { p.updateHeight(); Console.WriteLine(balanceFactor(p)); if (balanceFactor(p) == 2) { Console.WriteLine("rRot"); Console.WriteLine(balanceFactor(p.right)); if (balanceFactor(p.right) < 0) { Console.WriteLine("brRot"); p.right = rightRotation(p.right); } return(leftRotation(p)); } if (balanceFactor(p) == -2) { Console.WriteLine("lRot"); Console.WriteLine(balanceFactor(p.left)); if (balanceFactor(p.left) > 0) { Console.WriteLine("blRot"); p.left = leftRotation(p.left); } return(rightRotation(p)); } else { return(p); } }
private static int CONCAT(string str, bool isConsole) { var a = Stack.Pop(); var b = Stack.Pop(); Stack.Push(SimpleRope.Concat(a, b)); return(MyField.CurrentExecuteLine + 1); }
public static int balanceFactor(SimpleRope node) { if (node == null) { return(0); } else { return(getHeight(node.right) - getHeight(node.left)); } }
public static int getHeight(SimpleRope node) { if (node != null) { return(node.height); } else { return(0); } }
private static int PUSH(string str, bool isConsole) { string pattern = "\'.*'"; Regex rgx = new Regex(pattern); string newstr = rgx.Match(str).Value; var strRp = new SimpleRope(RefineString(newstr), null, null); Stack.Push(strRp); return(MyField.CurrentExecuteLine + 1); }
private static SimpleRope leftRotation(SimpleRope q) { SimpleRope qcopy = q; SimpleRope y = qcopy.right; SimpleRope T2 = y.left; y.left = q; qcopy.right = T2; qcopy.updateHeight(); y.updateHeight(); return(y); }
private static SimpleRope rightRotation(SimpleRope p) { SimpleRope pcopy = p; SimpleRope x = pcopy.left; SimpleRope T2 = x.right; x.right = pcopy; pcopy.left = T2; pcopy.updateHeight(); x.updateHeight(); return(x); }
private static int READ(string str, bool isConsole) { if (isConsole) { var strRp = new SimpleRope(Console.ReadLine(), null, null); Stack.Push(strRp); } else { var strRp = new SimpleRope(MyField.Input[MyField.CurrentReadPos], null, null); Stack.Push(strRp); } MyField.CurrentReadPos++; return(MyField.CurrentExecuteLine + 1); }
public static SimpleRope Concat(SimpleRope left, SimpleRope right) { SimpleRope lr = new SimpleRope(null, left, right); return(balance(lr)); }
public static void Edit(SimpleRope element, int depth) { array[positionTop + 1 - depth] = element; }
public static void Push(SimpleRope element) { positionTop++; array[positionTop] = element; }