void ex4_6() { std::cout << "ex4.6 \n"; std::vector<int> in; for (int sample = 0; sample < 10; ++sample) in.push_back(std::rand() % 2000); std::sort(in.begin(), in.end()); TreeNode<int>* node = createBST(in, 0, (int) in.size()) ; auto root = node; TreeNode<int>* rightmost = root; std::cout << "root.value=" << root->value << ", node.value=" << node->value << ", rightmost.value=" << rightmost->value << std::endl; rightmost = rightmost->right; rightmost = rightmost->right; auto next = getNextNode(rightmost); std::cout << "next node of node " << rightmost->value << " is " << (next ? next->value : -1 ) << std::endl; // std::cout << " sample size=" << in.size() << ", max height = " << height << ", log(size)=" << log2(in.size()) << std::endl; //std::cout << "is it a BST? " << checkBST(node); auto lists = createLists(node); for (int depth = 0; depth < lists.size(); ++depth) { std::cout << " level " << depth << ": "; for (auto elem : lists[depth]) { std::cout << elem->value << ", "; } std::cout << std::endl; } std::cout << "next node of node " << node->value << " is " << getNextNode(node)->value << std::endl; node = node->right; std::cout << "next node of node " << node->value << " is " << getNextNode(node)->value << std::endl; node = node->left; std::cout << "next node of node " << node->value << " is " << getNextNode(node)->value << std::endl; node = node->left; std::cout << "next node of node " << node->value << " is " << getNextNode(node)->value << std::endl; }
void GenericDataObjectFilter::setValue(const QVariant& value) { if (value != m_value) { m_value = value; createLists(); } }
int main() { // test queue struct node *head = NULL; head = createLists(); flatten(head); printList(head); return 0; }
void LinkBackFilter::setValue(const QVariant& value) { if (value != m_value) { m_value = value; createLists(); emit valueChanged(m_value); } }
//------------------------------------------------------------------------------- //! Constructor. //------------------------------------------------------------------------------- LearnWordDialog::LearnWordDialog(int num, QWidget *parent /* = NULL */) : QDialog(parent, Qt::WindowMinimizeButtonHint) , count(num) , currentIdx(0) { setupUi(this); createLists(); createActions(); installEventFilter(this); // set up dialog for first word next(); }
void ex4_4() { std::cout << "ex4.4 \n"; std::vector<int> in; for (int sample = 0; sample < std::rand() % 10000; ++sample) in.push_back(std::rand() % 20); std::sort(in.begin(), in.end()); auto node = createBST(in, 0, (int) in.size()) ; auto height = getHeight(node) ; std::cout << " sample size=" << in.size() << ", max height = " << height << ", log(size)=" << log2(in.size()) << std::endl; auto lists = createLists(node); for (int depth = 0; depth < lists.size(); ++depth) { std::cout << " level " << depth << ": "; for (auto elem : lists[depth]) { std::cout << elem->value << ", "; } std::cout << std::endl; } }
void loadGroupGroupList() { CONDITION cond; DMAN_GROUPNAMES g, criteria; char b[256]; if (createLists() == 0) return; memset(&g, 0, sizeof(g)); g.Type = DMAN_K_GROUPNAMES; criteria.Type = DMAN_K_GROUPNAMES; criteria.Flag = 0; cond = DMAN_Select(&dmanHandle, (DMAN_GENERICRECORD *) & g, (DMAN_GENERICRECORD *) & criteria, groupNamesList, NULL, NULL, NULL); if (cond != DMAN_NORMAL) { COND_DumpConditions(); return; } cond = extractGroups(groupNamesList, groupGroupList); if (cond != 1) return; MUT_LoadList(wGroupGroupList, groupGroupList, formatGroupGroup, b); (void) DMAN_ClearList(groupTitleList); MUT_LoadList(wGroupTitleList, groupTitleList, formatGroupTitle, b); }
void ex4_7() { std::cout << "ex4.7 \n"; std::vector<int> in; for (int sample = 0; sample < 10; ++sample) in.push_back(std::rand() % 2000); std::sort(in.begin(), in.end()); TreeNode<int>* node = createBST(in, 0, (int) in.size()) ; auto root = node; TreeNode<int>* rightmost = root; std::cout << "root.value=" << root->value << ", node.value=" << node->value << ", rightmost.value=" << rightmost->value << std::endl; rightmost = rightmost->right; TreeNode<int>* oneToLeft = rightmost->left; rightmost = rightmost->right; auto next = getNextNode(rightmost); std::cout << "next node of node " << rightmost->value << " is " << (next ? next->value : -1 ) << std::endl; // std::cout << " sample size=" << in.size() << ", max height = " << height << ", log(size)=" << log2(in.size()) << std::endl; //std::cout << "is it a BST? " << checkBST(node); auto lists = createLists(node); for (int depth = 0; depth < lists.size(); ++depth) { std::cout << " level " << depth << ": "; for (auto elem : lists[depth]) { std::cout << elem->value << ", "; } std::cout << std::endl; } //auto common = firstCommonAncestor(rightmost, oneToLeft); bool coversA = false; bool coversB = false; auto common = commonAncestorDescendRec(root, rightmost, oneToLeft, coversA, coversB); assert(common->value == 1709); coversA = false; coversB = false; // common = firstCommonAncestor(root, rightmost); common = commonAncestorDescendRec(root, root, rightmost, coversA, coversB); assert(common == nullptr); std::cout << "common ancestor = " << (common ? common->value : 0) << std::endl; }
//Adds the particles to the cell-Lists void CMolecularSystem::fillLists() { int cell,allCells,noc; createLists(); noc = this->parameter->noc; allCells = noc*noc*noc; for(int ti=0;ti<this->parameter->nop;ti++) { cellList[ti] = nilvalue; } for (int ci=0;ci<allCells;ci++) { cellHead[ci] = nilvalue; } for(int ti=0;ti<this->parameter->nop;ti++) { cell = get_cellByIndex(ti); this->molecules[ti].cell = cell; cellList[ti] = cellHead[cell]; cellHead[cell] = ti; } }
/* Calls relevant functions to play the game and allows user to guess letter after letter * and checks if the user has won or lost after each guess.*/ void userLoop(){ createLists(); // This reads the dictionary and generates an array of all lists of all word lengths char guess; // This is the variable where the current letter being guessed is kept int next=0; // Prevents duplication of code on first pass. int won=0; // Keeps track of whether the game has been won or lost int hard= difficulty(); //User chosen difficulty level int numberOfLetter=numberOfLetters(); //number of wrong guesses left before game is over int guessNumber=numberOfGuesses(); printf("To play, type in a single letter as a guess.\n"); printf("You have %i guesses remaining.\n", guessNumber); // game plays while the user still has some guesses left and has not won guess = obtainGuess(); //Gets first guess from user insertInList(&head, guess );//Puts guessed letter in list of guessed letters //All word families of user defined length are created generateDescriptions(&lists[numberOfLetter],numberOfLetter,guess); currentStatus(); // The status of game is shown to the user getNewList(hard); /*Finds the biggest members list from current *families and makes it the new main list of possible words*/ //This is the loop that allows the game to proceed. The first part of the loop is similar to above. while ((guessNumber)>0 && won==0) { if (next==1) {// prevents and initial duplication printf("You have %i guesses remaining.", guessNumber); // prints the status of the uncovered letters guess = obtainGuess(); //Gets first guess from user insertInList(&head, guess ); //Adds the guessed letter to the list containing all guessed letters currentFamily=NULL; //Resets list of current families //All word families of user defined length are created generateDescriptions(¤tWordList,numberOfLetter,guess); //All word families of user defined length are created /*Finds the biggest members list from current *families and makes it the new main list*/ getNewList(hard); currentStatus(); } // Allows the first part of the loop to be run on all subsequent guesses. next=1; // Lets the use know if they uncovered a letter. if (checkIfFound(guess,numberOfLetter)) { printf("\n \n \n Wrong!\n"); } else { printf("\n \n \n Correct.\n"); } // The number of guesses remaining decreases after each guess guessNumber--; // Checks to see if the user has uncovered all letters if (checkWin(numberOfLetter)) { printf("You Win!!"); won=1; } } printf("Game over. You uncovered:"); //Shows final game state currentStatus(); //Shows user a word that fits the currently visible letter pattern. printf("The word was: %s\n",currentFamily->members->word); }