#include #include "StringList.h" using namespace STRINGLIST; using namespace std; int main() { // Note that the client using our StringList class // has no idea how it is implemented StringList list; char test1[] = "hello there"; char test2[] = "second test"; char test3[] = "aabbcc"; list.insert(test1); list.print(); cout << "My string is: " << test1 << endl; list.insert(test2); test2[0] = 'x'; test2[1] = 'x'; test2[2] = 'x'; list.insert("dd ee ff"); list.insert("zzyyww"); list.insert("123ggg"); list.print(); list.insert(test3); list.print(); list.remove(test1); list.print(); // The example below shows how easy it is to // leak the internal representation by accident // This is an example of something that you shoud AVOID const Node *element = list.lookup(test3); if ( element ) { // Modifying a const data item will result in a compile time error //element->original[0] = 'a'; cout << "\nFound element " << element->original << endl; } else { cout << "\nElement not found" << endl; } list.print(); // Removing the string from the lsit list.remove(test3); // Inserting other stuff list.insert("something else"); // element is now a dangling pointer... // notice that the output can now be something other than what we would expect! cout << "Using the dangling pointer: " << element->original << endl; return 0; }