void check(String input) { for (int j = 0; j < input.length(); j++) { char ch = input.charAt(j); switch (ch) { case '{': case '[': case '(': exe.push(ch); break; case '}': case ')': case ']': output = exe.pop(); if ((output == '{' && ch != '}') || (output == '(' && ch != ')') || (output == '[' && ch != ']')) { System.out.println("Error: " + ch + "Missing at" + j); } else { System.out.println("Error: " + ch + "Not Missing here at" + j); } default: break; } System.out.println("2.Working"); } }
// --------------------------------------------------------------- public void mst() // minimum spanning tree using depth first search { // start at 0 --> mark and push vertexList[0].wasVisited = true; theStack.push(0); while (!theStack.isEmpty()) { int currentVertex = theStack.peek(); // get next unvisited neighbor int v = getAdjUnvisitedVertex(currentVertex); if (v == -1) // no more neighbors theStack.pop(); else { // mark and push the neighbor vertexList[v].wasVisited = true; theStack.push(v); // print out the path we just traveled displayVertex(currentVertex); displayVertex(v); System.out.print(" "); } } // Once stack is empty, we're done...reset flags for (int j = 0; j < nVerts; j++) vertexList[j].wasVisited = false; }
public static void main(String[] args) { StackX<Integer> theStack = new StackX<Integer>(10); theStack.push(20); theStack.push(40); theStack.push(60); theStack.push(80); while (!theStack.isEmpty()) { long value = theStack.pop(); System.out.print(value); System.out.print(" "); } System.out.println(""); }
public String doTrans() { for (int j = 0; j < input.length(); j++) { char ch = input.charAt(j); theStack.displayStack("For " + ch + " "); switch (ch) { case '+': case '-': gotOper(ch, 1); break; case '*': case '/': gotOper(ch, 2); break; case '(': theStack.push(ch); break; case ')': gotParen(ch); break; default: output = output + ch; break; } } while (!theStack.isEmpty()) { theStack.displayStack("While "); output = output + theStack.pop(); } theStack.displayStack("End "); return output; }
public void gotOper(char opThis, int prec1) { /* while(!theStack.isEmpty()) { char opTop=theStack.pop(); if(opTop == '(') { theStack.push(opTop); break; } else { int prec2; if(opTop == '+' || opTop == '-') prec2=1; else prec2=2; if(prec2<prec1) { theStack.push(opTop); break; } else output=output+opTop; } } */ theStack.push(opThis); }