int BinaryHeap::remove(int data){ BinaryNode* foundNode; foundNode = find(data); if(foundNode){ if(foundNode != last){ foundNode->data = last->data; last->data = data; } removeLast(); // Check to make sure root and last are not the same // otherwise set both to NULL and do not heapify if(!(foundNode == root && foundNode == last)){ heapify(foundNode); } else{ root = NULL; } return 1; } return 0; }
void BasicBlock::replaceLast(Procedure& proc, Value* value) { removeLast(proc); append(value); }
int main() { Node * head = NULL; FILE * fin = NULL; fin = openFile(); createWordNodes(fin,&head); printf("\n\n-----------Printing Original List-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp[6] = "frank"; Word * tempWord = createWordStruct(temp); addOrdered(tempWord, &head); printf("\n\n-----------Printing List Adding Ordered the name \"frank\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp1[6] = "AAAAA"; tempWord = createWordStruct(temp1); addFirst(tempWord, &head); printf("\n\n-----------Printing List Adding First the word \"AAAAA\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp2[6] = "ZZZZZ"; tempWord = createWordStruct(temp2); addLast(tempWord, &head); printf("\n\n-----------Printing List Adding Last the word \"ZZZZZ\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); char temp3[6] = "XXXXX"; tempWord = createWordStruct(temp3); addIndexed(tempWord, &head, 2); char prevWord[MAX], postWord[MAX]; strcpy(prevWord,((Word*)(head->next->data))->wrd); strcpy(postWord,((Word*)(head->next->next->next->data))->wrd); printf("\n\n-----------Printing List Adding at Index #2 the word \"XXXXX\"-----------\n\n"); printf("\n\n-----------It should be between the words \"%s\" and \"%s\"-----------\n\n", prevWord, postWord); printList(head); printf("\n\n\nBREAK\n\n\n"); removeFirst(&head); printf("\n\n-----------Printing List Removing First which will be the word \"AAAAA\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); removeLast(&head); printf("\n\n-----------Printing List Removing Last which will be the word \"ZZZZZ\"-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); printf("\n\n-----------Attempting to remove at index out of bounds-----------\n\n"); removeIndex(&head,-30); char word2Remove[MAX]; strcpy(word2Remove,((Word*)(head->next->next->data))->wrd); printf("\n\n-----------Attempting to remove at index 2 which will be: \"%s\"-----------\n\n", word2Remove); removeIndex(&head, 2); printf("\n\n-----------Printing list having removed %s-----------\n\n", word2Remove); printList(head); printf("\n\n\nBREAK\n\n\n"); printf("\n\n-----------Clearing (freeing) the entire list-----------\n\n"); clearList(&head); printf("\n\n-----------Attempting to print empty list-----------\n\n"); printList(head); printf("\n\n\nBREAK\n\n\n"); printf("\n\n-----------GOODBYE-----------\n\n"); fclose(fin); return 0; }// end main
/**** * * Test driver for exercising the functions of GeneralList. * */ int main() { char* intArray[] = {"1","2","3"}; // Intializing array GeneralList* listOfStrings; // Test list holding strings GeneralList* listOfIntegers; // Test list holding Integers /* * Allocate. */ listOfStrings = newGeneralList(); listOfIntegers = newGeneralListArray((char**) intArray, sizeof(intArray) / sizeof(char*)); /* * Call the constructive methods. */ putLast(putLast(putLast(listOfStrings, "x"), "y"), "z"); putFirst(putFirst(putFirst(listOfStrings, "c"), "b"), "a"); put(put(listOfStrings, "m", 3), "n", 4); set(listOfStrings, "N", 4); put(listOfIntegers, "4", 3); /* * Print out the results of the constructive methods. */ printf("\nConstruction results:\n"); printf("%s\n", toString(listOfStrings)); printf("%s\n", toString(listOfIntegers)); /* * Call the non-destructive access methods, printing out results * incrementally. */ printf( "\nFirst, last, and middle elements of string list are: %s, %s, %s\n", getFirst(listOfStrings), getLast(listOfStrings), get(listOfStrings, 3) ); /* * Call the destructive access methods, printing out results incrementally. */ printf( "\nRemoved first, last, and middle elements of string list are: %s, %s, %s\n", removeFirst(listOfStrings), removeLast(listOfStrings), removeIth(listOfStrings, 2) ); printf("String list after removals is: %s\n", toString(listOfStrings)); printf( "\nMore removed -- first, last, and middle elements of string list are: %s, %s, %s\n", removeIth(listOfStrings, 0), removeIth(listOfStrings, 3), removeIth(listOfStrings, 1) ); printf("String list after more removals is: %s\n", toString(listOfStrings)); /* * Put back some elements for utility method testing. */ put(put(put(listOfStrings, "b", 0), "N", 2), "y", 4); printf("String list after put backs: %s\n", toString(listOfStrings)); /* * Call the utility methods. */ printf( "\nResults of elementOf(\"b\"), elementOf(\"X\"), findIndex(\"N\"), findIndex(\"X\"):\n" ); printf("%s, %s, %d, %d\n", elementOf(listOfStrings, "b") ? "true" : "false", elementOf(listOfStrings, "X") ? "true" : "false", findIndex(listOfStrings, "N"), findIndex(listOfStrings, "X") ); printf("\nResults of sorting: %s\n", toString(sort(listOfStrings))); /* * Call the utility methods. */ printf( "\nResults of subList(2,3), length, isEmpty, equals, and toString:\n" ); printf("%s, %d, %s, %s, %s\n", toString(subList(listOfStrings, 2, 3)), length(listOfStrings), isEmpty(listOfStrings) ? "true" : "false", equals(listOfStrings, listOfIntegers) ? "true" : "false", toString(listOfStrings) ); /* * Do another sort. */ putLast(putLast(putLast(putLast(listOfStrings, "4"), "3"), "2"), "1"); printf("\nBefore 2nd sort: %s\n", toString(listOfStrings)); printf("Results of 2nd sort: %s\n", toString(sort(listOfStrings))); printf("\n"); return 0; }
// not finished yet. Value* evalLambda(Value* args, Environment* env){ if (!env || !args){ printf("Syntax error for lambda. Missing components here\n"); return NULL; } assert(args->type = cellType); Value *toCheck = getFirst(args); printf("start printing for lambda: "); printValue(toCheck); printf("\n"); if (getFirst(toCheck) && getFirst(toCheck)->type == openType){ Value *returnValue = (Value *)malloc(sizeof(Value)); returnValue->type = closureType; Closure *closure = initializeClosure(env); toCheck = getTail(toCheck); while (toCheck && getFirst(toCheck) && getFirst(toCheck)->type!=closeType){ push(closure->args, deepCopy(getFirst(toCheck))); toCheck = getTail(toCheck); } if (!toCheck || !getFirst(toCheck) || getFirst(toCheck)->type!=closeType){ printf("Syntax error for lambda. Missing parameters.\n"); destroyClosure(closure); return NULL; } reverse(closure->args); toCheck = getTail(args); if (!toCheck){ printf("lambda: bad syntax in: (lambda "); printValue(args); printf("\n"); destroyClosure(closure); return NULL; } removeLast(toCheck); printf("Show me the parse tree: "); printValue(toCheck); printf("\n"); closure->body = toCheck; returnValue->closureValue = closure; return returnValue; }else if (toCheck && toCheck->type==nullType){ Value *returnValue = (Value *)malloc(sizeof(Value)); returnValue->type = closureType; Closure *closure = initializeClosure(env); toCheck = getTail(args); removeLast(toCheck); closure->body = toCheck; returnValue->closureValue = closure; printf("Show me the parse tree: "); printValue(toCheck); printf("\n"); return returnValue; }else{ //printValue(); printf("Syntax error for lambda! Missing parameters.\n"); return NULL; } }
void CMyPaintDoc::resetHistory() { while(!m_history.isEmpty()) { removeLast(); } m_index = 0; }
void DataIconManager::injectWhileMerging(HkxObject *recessiveobj){ if (!getIsMerged() && recessiveobj){ auto recobj = static_cast<DataIconManager *>(recessiveobj); auto domchildren = getChildren(); auto recchildren = recobj->getChildren(); DataIconManager *domchild; DataIconManager *recchild; HkxSignature domsig; HkxSignature recsig; bool found; QVector <DataIconManager *> children; auto domvarbind = getVariableBindingSetData(); auto recvarbind = recobj->getVariableBindingSetData(); if (domvarbind){ domvarbind->merge(recvarbind); }else if (recvarbind){ getVariableBindingSet() = HkxSharedPtr(recvarbind); auto parfile = static_cast<BehaviorFile *>(getParentFile()); recobj->fixMergedIndices(parfile); parfile->addObjectToFile(recvarbind, -1); } for (auto i = 0; i < domchildren.size(); i++){ found = false; domsig = domchildren.at(i)->getSignature(); domchild = domchildren.at(i); for (auto j = 0; j < recchildren.size(); j++){ recsig = recchildren.at(j)->getSignature(); recchild = recchildren.at(j); if (domsig == recsig && domchild->getName() == recchild->getName()){ found = true; break; } } if (!found){ for (auto j = recchildren.size() - 1; j >= 0; j--){ recchild = recchildren.at(j); auto tempchildren = recchild->getChildren(); for (auto k = 0; k < tempchildren.size(); k++){ auto tempsig = tempchildren.at(k)->getSignature(); auto tempchild = tempchildren.at(k); if ((domsig == tempsig) && ((domchild->getName() == tempchild->getName())/* || //For FNIS problem in mt_behavior NPC_TurnLeft90 (domsig == HKB_CLIP_GENERATOR && !QString::compare(static_cast<hkbClipGenerator *>(domchild)->getAnimationName().section("\\", -1, -1), static_cast<hkbClipGenerator *>(tempchild)->getAnimationName().section("\\", -1, -1), Qt::CaseInsensitive))*/)) { insertObjectAt(i, recchild); if (!static_cast<BehaviorFile *>(getParentFile())->existsInBehavior(recchild)){ recchild->fixMergedIndices(static_cast<BehaviorFile *>(getParentFile())); recchild->fixMergedEventIndices(static_cast<BehaviorFile *>(getParentFile())); getParentFile()->addObjectToFile(recchild, -1); getParentFile()->addObjectToFile(recchild->getVariableBindingSetData(), -1); } //tempchildren.removeAt(k); for (auto m = 0; m < tempchildren.size(); m++){ tempchild = tempchildren.at(m); if (!static_cast<BehaviorFile *>(getParentFile())->existsInBehavior(tempchild)){ tempchild->fixMergedIndices(static_cast<BehaviorFile *>(getParentFile())); tempchild->fixMergedEventIndices(static_cast<BehaviorFile *>(getParentFile())); getParentFile()->addObjectToFile(tempchild, -1); getParentFile()->addObjectToFile(tempchild->getVariableBindingSetData(), -1); auto objects = static_cast<DataIconManager *>(tempchild)->getChildren(); while (!objects.isEmpty()){ auto obj = objects.last(); if (!static_cast<BehaviorFile *>(getParentFile())->existsInBehavior(obj)){ obj->fixMergedIndices(static_cast<BehaviorFile *>(getParentFile())); obj->fixMergedEventIndices(static_cast<BehaviorFile *>(getParentFile())); getParentFile()->addObjectToFile(obj, -1); getParentFile()->addObjectToFile(obj->getVariableBindingSetData(), -1); children = obj->getChildren(); } objects.removeLast(); objects = objects + children; children.clear(); } } } k = tempchildren.size(); j = -1; } } } } } setIsMerged(true); }else{ LogFile::writeToLog("DataIconManager::injectWhileMerging() hkbGenerator: nullptr!"); } }
// Linked list implementation interface void main(){ // Initialize variables int mode = 1; char input[256]; int add = 0; // Present options (clearing screen) each time while(mode != 8){ system("clear"); printf("Please choose an option for the linked list: \n"); printf(" 1. Add value\n 2. Add value to end\n 3. Remove value\n 4. Remove value from end\n"); printf(" 5. Clear all values\n 6. Test if empty\n 7. Length of list\n 8. Exit Program\n\n"); // Display the most recent list printf("Current list: "); print(); // Carry-over action for easy display switch(mode){ // Inform user of successful clearing case 5: printf("The list has been cleared.\n\n"); break; // Test list if empty case 6: if(isEmpty() == 1) printf("The list is currently empty.\n\n"); else printf("The list is not empty.\n\n"); break; // Print out length of list case 7: printf("Length: %d\n\n", length); break; // Do nothing default: break; } // Display option input printf("Option: "); scanf("%d", &mode); // Conduct user's action switch(mode){ // Add a value to beginning of list case 1: printf("\nPlease enter an integer to add to the list: "); scanf("%s", input); add = atoi(input); addFirst(add); printf("\n"); break; // Add a value to the end of the list case 2: printf("\nPlease enter an integer to add to the end of the list: "); scanf("%s", input); add = atoi(input); addLast(add); printf("\n"); break; // Remove value from beginning of list case 3: removeFirst(); break; // Remove value from end of list case 4: removeLast(); break; // Clear all values in the list case 5: clearList(); break; // Do nothing, tell user on next iteration case 6: break; // Do nothing, print length on next iteration case 7: break; // Do nothing, will exit program case 8: break; // Print out input warning default: printf("That is not a valid menu option. To quit, type '8'.\n"); break; } } // Reset terminal window system("clear"); }
T DLList<T>::dequeue(){ return removeLast(); }
bool removeLast(const T &item) { return removeLast([&] (const T &elt) -> bool {return elt==item;}); }
VlcMedia AbstractMediaList::takeLast() { VlcMedia item = last(); removeLast(); return item; }
Group::~Group() { while(!m_children.empty()) removeLast(); }
bool_t CMyList<T>::remove(T a_oItem) { bool_t fResult = true; Node oItemToRem(a_oItem); Node* temp = m_pFirstItem; while(temp) { if(oItemToRem.iValue == temp->iValue) { try { bool_t isFirst = false; bool_t isLast = false; //first item if(temp == m_pFirstItem) { fResult = removeFirst(); temp = m_pFirstItem->pNextItem; isFirst = true; } //last item if((false == isFirst))//if one element was in the list is need to check if poiter was deleted { if(0 == temp->pNextItem) { fResult = removeLast(); isLast = true; break; } } //else if(false == isFirst && false == isLast) { Node* toRem = temp; Node* iterator = m_pFirstItem; while(iterator) { if(oItemToRem.iValue == iterator->pNextItem->iValue) { iterator->pNextItem = temp->pNextItem; temp = iterator; break; } iterator = iterator->pNextItem; } delete toRem; iItemsCounter--; } } catch(...) { fResult = false; } } if(temp != 0) temp = temp->pNextItem; } return fResult; }
void MainWindow::populateNodeMenu(QMenu* menu, bool recenter, Viewport* v) { QDirIterator bitr(App::instance()->bundledNodePath(), QDirIterator::Subdirectories); QDirIterator uitr(App::instance()->userNodePath(), QDirIterator::Subdirectories); QList<QRegExp> title_regexs= {QRegExp(".*title\\('+([^']+)'+\\).*"), QRegExp(".*title\\(\"+([^\"]+)\"+\\).*")}; // Extract all of valid filenames into a QStringList. QStringList node_filenames; for (auto itr : {&bitr, &uitr}) { while (itr->hasNext()) { auto n = itr->next(); if (n.endsWith(".node")) node_filenames.append(n); } } // Sort the list, then populate menus. QMap<QString, QPair<QStringList, NodeConstructorFunction>> nodes; QStringList node_titles; for (auto n : node_filenames) { QFile file(n); if (!file.open(QIODevice::ReadOnly)) continue; QTextStream in(&file); QString txt = in.readAll(); // Find the menu structure for this node auto split = n.split('/'); while (split.first() != "nodes") split.removeFirst(); split.removeFirst(); // Attempt to extract the title with a regex; // falling back to the node's filename otherwise. QString title = split.last().replace(".node",""); split.removeLast(); for (auto& regex : title_regexs) if (regex.exactMatch(txt)) title = regex.capturedTexts()[1]; QString name = "n*"; if (title.size() > 0 && title.at(0).isLetter()) name = title.at(0).toLower() + QString("*"); NodeConstructorFunction constructor = [=](Graph *r){ return new Node(name.toStdString(), txt.toStdString(), r); }; nodes[title] = QPair<QStringList, NodeConstructorFunction>( split, constructor); node_titles.append(title); } // Put all of the nodes into the Add menu, deferring Export nodes // until the end (after a separator). node_titles.sort(); QStringList deferred; for (auto title : node_titles) if (nodes[title].first.contains("Export")) deferred << title; else addNodeToMenu(nodes[title].first, title, menu, recenter, nodes[title].second, v); menu->addSeparator(); for (auto title : deferred) addNodeToMenu(nodes[title].first, title, menu, recenter, nodes[title].second, v); }