void test4() { DLList list; list << 1 << 1 << 2 << 3 << 5 << 8 << 13 << 21 << 34 << 55 << 89; std::cout<<"List:"<<std::endl; list.print(); std::cout<<std::endl<<"Sorted list:"<<std::endl; list.printSorted(); std::cout<<std::endl<<"List:"<<std::endl; list.print(); }
void test3() { DLList list; int dave; list << 1 << 1 << 1 << 0 << 0 << 12 << 123123; std::cout<<"List:"<<std::endl; list.print(); std::cout<<std::endl<<"Removing last index..."<<std::endl<<std::endl; std::cout<<"List:"<<std::endl; bool saved = list.removeLast(dave); list.print(); std::cout<<std::endl; std::cout<<"Removed element: "<<dave<<std::endl; std::cout<<"Success? "<<((saved) ? "Yes." : "No.")<<std::endl; }
void test1() { DLList list; list << 1 << 2 << 12 << 13 << 11 << 22; std::cout<<"List:"<<std::endl; list.print(); }
void test5() { DLList list1, list2; for (int x = 0; x < 100; ++x) { if (x % 4 == 0) list1 << x; if (x % 5 == 0) list2 << x; } std::cout<<"List1:"<<std::endl; list1.print(); std::cout<<std::endl; std::cout<<"List2:"<<std::endl; list2.print(); std::cout<<std::endl; std::cout<<"Intersection:"<<std::endl; DLList * intersect = list1.intersection(list2); intersect->print(); delete intersect; }
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(); }