C++ STL List Container C++ STL list container Examples Word puzzle using C++/STL list container STL list is used to maintain the word dictionary Maximum subsequence program
Important C++ STL list container interface size() empty() clear() front()/back() push_back()/push_front() pop_back()/pop_front() insert(i, x) erase(i), erase(start, end) begin()/end() remove() List<T>::iterator/List<T>::const_iterator
Import list member functions reverse(): reverse elements in list sort(): sort elements in list Stable sort (relative order of equal elements are respected) uniqe(): remove duplicate elements Example: delete duplicate elements remove_duplicate.cpp
Word Puzzle Word puzzle program has been re-written to use C++ STL list container to maintain the word list All other parts are the same as the first implementation as STL vector See examples/r4 word_puzzle_list.h word_puzzle_list.cpp rotation.cpp Makefile words.txt // word dictionary puzzle1.txt // a puzzle Review the code A demo of running the program
MSS: Maximum SubSequence Problem Computing maximum subsequence as given in the textbook See examples/r4 Mss_problem.txt // problem description Mss.cpp // source code Mss.input1 Mss.output1 To compile: make mss.x Review the code A demo of running the program
size() of List: Recursive Implementation A problem to consider Assuming that we do not maintain theSize member variable, how do we determine the number of elements in a list using a recursive function? See examples/r4 list_size1.cpp (using Node pointer) list_size2.cpp (using iterator) Note that in essence, they are the same