void TestPrepend(DoubleLinkedList<int> & alist) { DoubleLinkedList<int> blist; std::cout << "\n********** Prepend **********" << std::endl; // Full List alist.Prepend(4); alist.Prepend(3); alist.Prepend(2); alist.Prepend(1); alist.Prepend(0); std::cout << alist.First() << std::endl; std::cout << alist.Last() << std::endl; // Empty List blist.Prepend(100); blist.Prepend(200); blist.Prepend(300); blist.Prepend(400); blist.Prepend(500); std::cout << blist.First() << std::endl; std::cout << blist.Last() << std::endl; }
void TestExtract() { DoubleLinkedList<int> alist; std::cout << "\n********** Extract **********" << std::endl; // Empty List try { alist.Extract(0); } catch (char * msg) { std::cout << msg << std::endl; } // Head and Tail are the same alist.Append(0); alist.Extract(0); try { std::cout << alist.First() << std::endl; } catch (char * msg) { std::cout << msg << std::endl; } try { std::cout << alist.Last() << std::endl; } catch (char * msg) { std::cout << msg << std::endl; } // Remove Head alist.Append(0); alist.Append(1); alist.Extract(0); std::cout << alist.First() << std::endl; std::cout << alist.Last() << std::endl; // Remove Tail alist.Prepend(0); alist.Extract(1); std::cout << alist.First() << std::endl; std::cout << alist.Last() << std::endl; }
void TestExtract() { DoubleLinkedList<int> alist; std::cout << "\n********** Testing: DoubleLinkedList Extract **********" << std::endl; std::cout << "\n********** Testing: Extract with empty list**********" << std::endl; try { //Note: The parameter is the DATA to be removed alist.Extract(0); } catch (const char * msg) { std::cout << msg << std::endl; } std::cout << "\n********** Testing: Extract removing only node **********" << std::endl; alist.Append(0); alist.Extract(0); try { std::cout << alist.First() << std::endl; } catch (const char * msg) { std::cout << msg << std::endl; } try { std::cout << alist.Last() << std::endl; } catch (const char * msg) { std::cout << msg << std::endl; } std::cout << "\n********** Testing: Extract removing head **********" << std::endl; alist.Append(0); alist.Append(1); alist.Extract(0); std::cout << alist.First() << std::endl; std::cout << alist.Last() << std::endl; std::cout << "\n********** Testing: Extract removing tail **********" << std::endl; alist.Prepend(0); alist.Extract(1); std::cout << alist.First() << std::endl; std::cout << alist.Last() << std::endl; std::cout << "\n********** Testing: Extract removing non-existing node **********" << std::endl; alist.Append(0); alist.Append(1); try { alist.Extract(99); } catch (const char * msg) { std::cout << msg << std::endl; } }