void testPart4(BinarySearchTree<BSTNode1<int>, int> *tree) { cout << "Testing Part 4..." << endl; cout << "______________________________" << endl; DLList<int> list = tree->getLE(10); cout << "All items in tree less than 10: "; for(int n = 1; n < list.size(); n++){ cout << list.get(n) << ", "; } cout << endl; }
//- merge the input list, merge_list, with the current list, making //- sure not to add duplicate items into the current list void DLList::merge_unique ( DLList& merge_list, int merge_list_unique ) { // MJP Note: // This procedure could be much more efficient if sorted lists // are used. However, I need this procedure at this time to merge // DLLists that already exist. These were not created as sorted // lists (SDLLists) and it would be painful to convert them to // SDLLists. It would be a lot easier if one could simply sort // a DLList based on the numeric values of its items. // Save the current index of the merge_list int current_index = merge_list.index; int old_size = size(); int i, j, check_index; void* new_item = NULL; for (i = 0; i < merge_list.size(); i++) { // Get the item from the merge_list and insert it into "this" // list if it doesn't already exist there. new_item = merge_list.get_item_and_step(); check_index = merge_list_unique ? old_size : size(); for ( j = 0; j < check_index; j++ ) { if ( listArray[j] == new_item ) { check_index = -1; break; } } if ( check_index != -1 ) append_link(new_item); } // Restore the original index of the merge_list merge_list.index = current_index; }
void LRUCache::fetchPage(int pageNumber) { /* find the page in the map */ unordered_map< int, Node* >::const_iterator it = directAccess.find(pageNumber); /* if the page is found in the map */ if (it != directAccess.end()) { /* move the page on to the head of the doubly list */ dlist.moveToHead( (Node*)it->second); } else { /* if size of list is full */ if (dlist.size() == cacheSize-1) dlist.removeTail(); /* add the node to the head of doubly list */ Node* node = dlist.addNode(pageNumber); /* add the node in the map */ directAccess.insert(pair< int, Node* >(pageNumber,node)); } dlist.print(); }
int main(){ DLList<int> leven; for(int i = 0; i<30; i++){ leven.add(i); } DLList<int> lodd = leven.deal(); for(int i =0; i<leven.size(); i++){ cout <<"entry "<< i << " of leven " << leven.get(i)<< endl; } for(int i =0; i<lodd.size(); i++){ cout <<"entry "<< i << " of lodd " << lodd.get(i)<< endl; } DLList<int> lr; for(int i = 0; i<20; i++){ lr.add(i); } for(int i =0; i<lr.size(); i++){ cout <<"entry before rotate "<< i << " of lr " << lr.get(i)<< endl; } lr.Rotate(5); for(int i =0; i<lr.size(); i++){ cout <<"entry after rotate "<< i << " of lr " << lr.get(i)<< endl; } DLList<int> l1; DLList<int> l2; l1.add(1); l1.add(2); l1.add(3); l1.add(4); l2.add(5); l2.add(6); l2.add(7); l2.add(8); cout<<"before absorb" << endl; for(int i =0; i<l1.size(); i++){ cout <<"entry of l1 "<< i << " of l1 " << l1.get(i)<< endl; } for(int i =0; i<l2.size(); i++){ cout <<"entry of l2 "<< i << " of l2 " << l2.get(i) <<endl; } l1.Absorb(l2); cout<<"after absorb" << endl; for(int i =0; i<l1.size(); i++){ cout <<"entry of l1 "<< i << " of l1 " << l1.get(i)<< endl; } for(int i =0; i<l2.size(); i++){ cout <<"entry of l2 "<< i << " of l2 " << l2.get(i) <<endl; } DLList<int> l; l.add(5); l.add(5); l.add(5); l.add(5); cout << "True " << l.IsPalindrome()<< endl; l.add(6); cout << "Now False " << l.IsPalindrome()<< endl; }