void LongestIncreasingSeq::RecursivePrint( int n, int length) { if(length == 0) return; else { RecursivePrint( path[n], length - 1); std::cout<< xSeq[n] <<" "; } }
void RecursivePrint(RegExpressionT *e) { switch(e->type) { case ATOM: printf("%c", e->value); goto check; case CHARSET: printf("@"); goto check; case ANYCHAR: printf("."); goto check; case EMPTY: printf("&"); goto check; case KLEENE: printf("("); RecursivePrint(e->term); printf(")"); printf("*"); goto check2; case POSCLOSE: printf("("); RecursivePrint(e->term); printf(")"); printf("+"); goto check2; case OPTION: printf("("); RecursivePrint(e->term); printf(")"); printf("?"); goto check2; case UNION: printf("("); RecursivePrint(e->term); printf("|"); RecursivePrint(e->next); printf(")"); break; case CONCAT: printf("("); RecursivePrint(e->term); RecursivePrint(e->next); printf(")"); break; } return; check: if(e->term)printf("\nError 1 - nonterminal\n"); check2: if(e->next)printf("\nError 2 - nonterminal\n"); }
void LongestIncreasingSeq::printAnswer() { RecursivePrint(maxIndex, opt[maxIndex]); }
/** * This will loop through the file and extract XML Data. * @param _fileName the path to the file which will be read */ int XMLReader(string _fileName) { ifstream infile; // Input file stream for XML file to parse int intLineCount = 0; // Keep track of line number string strLine = ""; // Hold current line while parsing XML file vector<Element*> vecElementStack; // Will hold all tag names and tag lines string previousElementName = ""; // The tag name of the previous element on the vector (stack) ParserState currentState = STARTING_DOCUMENT; // Will hold state of previously read line Element* rootElement = NULL; infile.open(_fileName, ifstream::in); if ( infile.fail() ) { cerr << "Error opening '" << _fileName << "'" << endl ; return EXIT_FAILURE; } else { // Loop through the file do { // Increment line counter intLineCount++; // Read a new line from the file getline(infile, strLine); // Get tag name of previous open tag element (will return "" if none) previousElementName = getLastElement(vecElementStack); // Get state of newly read line currentState = GetXMLData(strLine, currentState); // Handle parser state specific actions if (currentState == ELEMENT_OPENING_TAG) //########################## HERE { Element* tempElement = new Element(intLineCount, strLine, vecElementStack.size(), currentState); tempElement->addAttribute(getAttributes(strLine)); if (rootElement == NULL) // First time adding to the tree { rootElement = tempElement; } else { (vecElementStack[ vecElementStack.size() - 1 ])->addChild( tempElement ); } vecElementStack.push_back(tempElement); previousElementName = getLastElement(vecElementStack); } else if (currentState == ELEMENT_CLOSING_TAG) { if (previousElementName != getClosingTagName(strLine)) { // if open tag name != closing tag name cout << endl << "*******************************************" << endl; cout << "ERROR: Invalid closing tag at Line " << intLineCount << endl; cout << "REASON: " << previousElementName << " != " << getClosingTagName(strLine) << endl; cout << "ABORTING..." << endl; cout << "*******************************************" << endl; return EXIT_FAILURE; } vecElementStack.pop_back(); } else if (currentState == ELEMENT_NAME_AND_CONTENT) { Element* tempElement = new Element(intLineCount, strLine, vecElementStack.size(), currentState); tempElement->addAttribute(getAttributes(strLine)); (vecElementStack[ vecElementStack.size() - 1 ])->addChild( tempElement ); } else if (currentState == ERROR) { removeWhiteSpace(strLine); cout << endl << "*******************************************" << endl; cout << "ERROR: Something went wrong!" << endl; cout << "~~ Line " << intLineCount << ": " << strLine << endl; cout << "ABORTING..." << endl; cout << "*******************************************" << endl; return EXIT_FAILURE; } printXMLData(vecElementStack, currentState, intLineCount, strLine, previousElementName); cout << endl; } while (infile.good()); cout << endl << endl << endl << "TREE OUTPUT" << endl; cout << "********************************************************" << endl; RecursivePrint(rootElement); deleteVectorData(vecElementStack); } }
void RecursivePrint( Element* root ) { vector<Element*> children = root->getChildElements(); string spaces; // if ROOT ELEMENT if (root->getTreeLevel() == 0) { cout << "[" << root->getTreeLevel(); cout << "] '" << root->getTagName(); cout << "' has " << root->getChildElements().size() << " direct children " << endl; } for (Element* child : children) { spaces = ""; for(int i = 0; i < child->getTreeLevel(); i++) { if (i == child->getTreeLevel() - 1) { spaces += "|||"; } else { spaces += "| "; } } cout << spaces << "[" << child->getTreeLevel(); cout << "] '" << child->getTagName(); if (child->getChildElements().size() == 1) { cout << "' has 1 direct child"; } else { cout << "' has " << child->getChildElements().size() << " direct children"; } int numAttributes = child->getAttributes().size(); if (numAttributes > 0) { if (numAttributes == 1) { cout << " and " << numAttributes << " attribute { "; } else { cout << " and " << numAttributes << " attributes { "; } for ( Attributes* arg : child->getAttributes()) { cout << arg->getAttributeInfo() << " "; } cout << "}"; } cout << endl; RecursivePrint(child); } }
void MCTSNode::ToAsciiArt(std::ostream& stream, uint max_children, uint max_level, Player pl) const { RecursivePrint(stream, max_children, max_level, 0, pl); }
void TestRegExp(RegExpressionT *e) { if (!e) { printf("invalid\n"); return; } RecursivePrint(e); printf("\n"); }