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; } }