void Password::guess(int try_password, int num_matches) //index of guessed word in the list of all words (1-based), number of matches reported by fallout 3, update viable passwords list { String* temp = all_words->get(try_password); //gets word guessed ListArray<String>* temp_array = new ListArray<String>(); ListArrayIterator<String>* iter = viable_words->iterator(); String* yak = all_words->get(try_password); while(iter->hasNext()) { String* blah = iter->next(); int matches = getNumMatches(blah, yak); //call getNumMatches if(num_matches == matches) { temp_array->add(blah); } } delete viable_words; viable_words = temp_array; }
int main() { ListArray<CD>* cds = CD::readCDs("cds.txt"); int num_items = cds->size(); cout << num_items << endl; while(true) { HeapSkew<CD>* sh = new HeapSkew<CD>(&CD::compare_items); ListArrayIterator<CD>* iter = cds->iterator(); while(iter->hasNext()) { CD* cd = iter->next(); sh->heapInsert(cd); } delete iter; /*while(!(sh->heapIsEmpty())) { CD* cd = sh->heapRemove(); cd->displayCD(); }*/ delete sh; } deleteCDs(cds); delete cds; return 0; }
int main() { ListArray<CD>* cds = CD::readCDs("cds.txt"); int num_items = cds->size(); cout << num_items << endl; TableSortedList<CD>* slt = new TableSortedList<CD>(&CD::compare_items, &CD::compare_keys); //DO THIS //thoroughly test your table ListArrayIterator<CD>* iter = cds->iterator(); if(slt->tableIsEmpty()) { int count = 0; while(iter->hasNext()) { CD* cd = iter->next(); slt->tableInsert(cd); count++; } } ListDoublyLinkedIterator<CD>* iter2 = slt->iterator(); /*while(iter2->hasNext()) { CD* myCD = iter2->next(); myCD->getKey()->displayString(); cout << endl; }*/ String* title = new String("Manifesto"); bool rem = slt->tableRemove(title); if (rem) cout << "Removed item" << endl << endl; while(iter2->hasNext()) { CD* myCD = iter2->next(); myCD->getKey()->displayString(); cout << endl; } cout << endl; cout << slt->tableSize() << endl; delete title; deleteCDs(cds); delete cds; delete slt; return 0; }
void Password::displayViableWords() //display the current list of possible passwords { ListArrayIterator<String>* display = viable_words->iterator(); while(display->hasNext()) { String* aha = display->next(); aha->displayString(); cout << endl; } }
Password::~Password() //(there is work to do here, delete the individual words) { ListArrayIterator<String>* iter = all_words->iterator(); while(iter->hasNext()) { String* temp = iter->next(); delete temp; } delete all_words; delete viable_words; }
void deleteCDs(ListArray<CD>* list) { ListArrayIterator<CD>* iter = list->iterator(); while(iter->hasNext()) { CD* cd = iter->next(); delete cd; } delete iter; }
Permutation::~Permutation() { ListArrayIterator<Integer>* iter = numbers->iterator(); while(iter->hasNext()) { Integer* i = iter->next(); delete i; } delete iter; delete numbers; }
void Password::displayViableWords() { ListArrayIterator<String>* iter = viable_words->iterator(); while(iter->hasNext()) { String* w = iter->next(); w->displayString(); cout << "/n"; } delete iter; }
void addCDs(ListArray<CD>* list, Hybrid<CD>* h) { ListArrayIterator<CD>* iter = list->iterator(); while(iter->hasNext()) { CD* cd = iter->next(); h->enqueue(cd); } delete iter; }
Password::~Password() { ListArrayIterator<String>* iter = all_words->iterator(); while(iter->hasNext()) { String* Dword= iter->next(); delete Dword; } delete iter; delete viable_words; delete all_words; }
//callback bool InputManager::keyReleased(const OIS::KeyEvent& e) { //cout << "KR" << endl; //notify each of the listeners ListArrayIterator<InputListener>* iter = input_listeners->iterator(); while(iter->hasNext()) { InputListener* listener = iter->next(); listener->keyReleased(keyMap(e)); } delete iter; return true; }
void Password::guess(int try_password, int num_matches) { String* guessed_word = all_words->get(try_password); ListArray<String>* new_list = new ListArray<String>(); ListArrayIterator<String>* itr = viable_words->iterator(); while(itr->hasNext()) { String* comp_word = itr->next(); int matched = getNumMatches(guessed_word,comp_word); if(matched == num_matches) new_list->add(comp_word); } delete viable_words; viable_words = new_list; }
//callback bool InputManager::mouseMoved(const OIS::MouseEvent& e) { //cout << "MM" << endl; //notify each of the listeners ListArrayIterator<InputListener>* iter = input_listeners->iterator(); while(iter->hasNext()) { InputListener* listener = iter->next(); int x_loc = (int) e.state.X.abs * (window_width / 50.0); int y_loc = (int) e.state.Y.abs * (window_height / 50.0); float x_rel = e.state.X.rel; float y_rel = e.state.Y.rel; listener->mouseMoved(x_loc, y_loc, x_rel, y_rel); //current location of the mouse (absolute coords and relative coords) } delete iter; return true; }
//callback bool InputManager::mouseReleased(const OIS::MouseEvent& e, OIS::MouseButtonID id) { //cout << "MR" << endl; //notify each of the listeners ListArrayIterator<InputListener>* iter = input_listeners->iterator(); while(iter->hasNext()) { InputListener* listener = iter->next(); std::string game_mouse = mouseMap(id); int x_loc = (int) e.state.X.abs * (window_width / 50.0); int y_loc = (int) e.state.Y.abs * (window_height / 50.0); listener->mouseReleased(x_loc, y_loc, game_mouse); //absolute location of mouse when released and which button was released } delete iter; return true; }
int main() { //the unsorted ListArray of cds ListArray<CD>* cds = CD::readCDs("cds.txt"); int num_items = cds->size(); cout << num_items << endl; cout << endl; //test the binary search tree //insert all of the cds ListArrayIterator<CD>* iter = cds->iterator(); BinarySearchTree<CD>* bst = new BinarySearchTree<CD>(&CD::compare_items, &CD::compare_keys); while(iter->hasNext()) { CD* cd = iter->next(); bst->insert(cd); } delete iter; //DO THIS //test your tree sort method CD** unsorted_cds = cds->toArray(); CD** sorted_cds = BinarySearchTree<CD>::treeSort(unsorted_cds, num_items, &CD::compare_items, &CD::compare_keys); for (int i = 0; i < num_items; i++) { sorted_cds[i]->getKey()->displayString(); cout << endl; } deleteCDs(cds); delete cds; return 0; }
void deleteCDs(ListArray<CD>* list) { ListArrayIterator<CD>* iter = list->iterator(); //DO THIS //iterate over and delete the cds while(iter->hasNext()) { CD* cd = iter->next(); delete cd; } delete iter; }
void addCDs(ListArray<CD>* list, ListBox<CD>* lb) { ListArrayIterator<CD>* iter = list->iterator(); //DO THIS //iterate over and add the cds to the list box (use lb->addItem) while(iter->hasNext()) { CD* cd = iter->next(); lb->addItem(cd); } delete iter; }
int main() { ListArray<CD>* cds = CD::readCDs("cds.txt"); int num_items = cds->size(); cout << num_items << endl; TableSortedList<CD>* slt = new TableSortedList<CD>(&CD::compare_items, &CD::compare_keys); //DO THIS //thoroughly test your table ListArrayIterator<CD>* iter = cds->iterator(); String* titles[310]; CD* cds2[310]; int count = 0; CD* duplicateTest; // test duplicate CD to be added later while(iter->hasNext()) { CD* cd = iter->next(); duplicateTest = cd; cds2[count]=cd; titles[count]=cds2[count]->getKey(); count++; slt->tableInsert(cd); } delete iter; slt->tableInsert(duplicateTest); // Program should not insert this CD because it is a duplicate cout << "Table size after inserting all CDs is " << slt->tableSize() << endl; // If insert works correctly, size should be 310 (If duplicate was added, it would be 311) for(count = 0; count < 310; count++) { CD* cdRetrieve = slt->tableRetrieve(titles[count]); // testing the retrieve function, it should be able to find all 310 CDs if (cdRetrieve == NULL) cout << "Couldn't find CD" << endl; else cout << "Found CD #" << count+1 << endl; } count = 1; ListDoublyLinkedIterator<CD>* iter2 = slt->iterator(); // Testing the SLDL iterator, every CD should be displayed while(iter2->hasNext()) { CD* cd3 = iter2->next(); cout << "\nThis is CD #" << count << ":" << endl << endl; count++; cd3->displayCD(); } for(int i = 0; i < 310; i++) { slt->tableRemove(titles[i]); } cout << "Table size after removing all CDs is " << slt->tableSize(); // Table size should be 0 after removing everything deleteCDs(cds); delete cds; delete slt; return 0; }
int main() { ListArray<CD>* cds = CD::readCDs("cds.txt"); int num_items = cds->size(); cout << num_items << endl; TableSortedList<CD>* slt = new TableSortedList<CD>(&CD::compare_items, &CD::compare_keys); //DO THIS //thoroughly test your table ListArrayIterator<CD>* addCDs = cds->iterator(); while (addCDs->hasNext()) { slt->tableInsert(addCDs->next()); } cout << "\nSize after adding CDs: " << slt->tableSize() << endl; String* sk = new String("Omnivium"); cout << "Retrieving " << "Omnivium" << "..." << endl; slt->tableRetrieve(sk)->displayCD(); cout << "\nSize after retrieval: " << slt->tableSize() << endl; cout << "\n\nRemoving " << "Omnivium" << "..." << endl; bool isDelete = slt->tableRemove(sk); cout << "Successful? "; if (isDelete) cout << "Yes"; else cout << "No"; sk = new String("Programmed To Consume"); cout << "\n\nRemoving " << "Programmed to Consume" << "..." << endl; isDelete = slt->tableRemove(sk); cout << "Successful? "; if (isDelete) cout << "Yes"; else cout << "No"; cout << "\n\n\nSize after removal: " << slt->tableSize() << endl; sk = new String("My Little Pony Anthology"); cout << "\n\nRemoving item not in table, " << "My Little Pony Anthology" << "..." << endl; isDelete = slt->tableRemove(sk); cout << "Successful? "; if (isDelete) cout << "Yes"; else cout << "No"; cout << "\n\n\nSize after removal: " << slt->tableSize() << endl; sk = new String("Back in Black"); cout << "\n\nRetrieving item not in table, " << "Back in Black" << "..." << endl; cout << "\n\nInserting duplicates..." << endl; ListArray<CD>* cds2 = CD::readCDs("cds.txt"); ListArrayIterator<CD>* addCDs2 = cds2->iterator(); while (addCDs2->hasNext()) { slt->tableInsert(addCDs2->next()); } //finished size should be 310 since removed CDs are re-added cout << "Size after inserting duplicates: " << slt->tableSize(); cout << "\n\n\nIs the table empty? "; if (!slt->tableIsEmpty()) cout << "No"; else cout << "Yes"; cout << "\n\n\nRemoving all CDs..." << endl; slt->~TableSortedList(); //deconstruct ALL THE THINGS cout << "\n\nIs the table empty? "; if(!slt->tableIsEmpty()) cout << "No"; else cout << "Yes"; deleteCDs(cds); delete cds; delete slt; return 0; }
int main() { //the unsorted ListArray of cds ListArray<CD>* cds = CD::readCDs("cds.txt"); int numItems = cds->size(); cout << numItems << endl; cout << endl; //test the binary search tree //insert all of the cds ListArrayIterator<CD>* iter = cds->iterator(); BinarySearchTree<CD>* bst = new BinarySearchTree<CD>(&CD::compare_items, &CD::compare_keys); while(iter->hasNext()) { CD* cd = iter->next(); bst->insert(cd); } delete iter; BinaryTreeIterator<CD>* bst_iter = bst->iterator(); bst_iter->setInorder(); //takes a snapshot of the data while(bst_iter->hasNext()) { CD* cd = bst_iter->next(); //cd->displayCD(); } delete bst_iter; int height = bst->getHeight(); bool balance = bst->isBalanced(); if(balance == true) { cout << "\nThe height is " << height << " and it is balanced.\n"; } else { cout << "\nThe height is " << height << " and it is not balanced.\n"; } //create a minimum height binary search tree BinarySearchTree<CD>* min_bst = bst->minimize(); bst_iter = min_bst->iterator(); //make sure that an inorder traversal gives sorted order bst_iter->setInorder(); //takes a snapshot of the data while(bst_iter->hasNext()) { CD* cd = bst_iter->next(); //cd->displayCD(); } delete bst_iter; height = min_bst->getHeight(); balance = min_bst->isBalanced(); if(balance == true) { cout << "\nThe minimum height is " << height << " and it is balanced.\n"; } else { cout << "\nThe minimum height is " << height << " and it is not balanced.\n"; } //create a complete binary search tree BinarySearchTree<CD>* complete_bst = bst->minimizeComplete(); delete bst; //make sure that an inorder traversal gives sorted order bst_iter = complete_bst->iterator(); bst_iter->setInorder(); //takes a snapshot of the data while(bst_iter->hasNext()) { CD* cd = bst_iter->next(); //cd->displayCD(); } delete bst_iter; height = complete_bst->getHeight(); balance = complete_bst->isBalanced(); if(balance == true) { cout << "\nThe minimum height is " << height << " and it is balanced.\n"; } else { cout << "\nThe minimum height is " << height << " and it is not balanced.\n"; } delete complete_bst; deleteCDs(cds); delete cds; return 0; }