public void check() { int stackSize = _input.Length; //get max stack size StackX theStack = new StackX(stackSize); //make stack for (int j = 0; j < _input.Length; j++) { char ch = _input[j]; switch (ch) { case '{': case '[': case '(': theStack.push(ch); //push to stack break; case '}': case ']': case ')': if (!theStack.isEmpty()) { char chx = theStack.pop(); if ((ch == '}' && chx != '{') || (ch == ']' && chx != '[') || (ch == ')' && chx != '(')) { Console.WriteLine("Error: " + ch + " at " + j); } } else { Console.WriteLine("Error: " + ch + " at " + j); } break; default: break; } } //at this point all characters have been processed if (!theStack.isEmpty()) { Console.WriteLine("Error: Missing right delimter"); } }
public string DoRev() { int stackSize = _input.Length; StackX theStack = new StackX(stackSize); for (int j = 0; j < _input.Length; j++) { char ch = _input[j]; //get char at index theStack.push(ch); //push it } _output = ""; while (!theStack.isEmpty()) { char ch = theStack.pop(); _output = _output + ch; } return(_output); }