#include #include #include #include #include #include #include using namespace std; int random_in_range(int min, int max) { return random() % (max - min + 1) + min; } string random_string(int min_length, int max_length) { string result; result += (char)random_in_range('A', 'Z'); int len = random_in_range(min_length, max_length); for (int i = 1; i data; ptr = ptr->next; return result; } }; list() { first = NULL; last = NULL; } void clear() { while (first != NULL) { link * next = first->next; delete first; first = next; } last = NULL; } ~list() { clear(); } bool empty() const { return first == NULL; } enumerator get_enumerator() const { return enumerator(first); } void add_to_front(string s) { if (first == NULL) { first = new link(s); last = first; } else first = new link(s, first); } void add_to_end(string s) { if (first == NULL) { first = new link(s); last = first; } else { last->next = new link(s); last = last->next; } } string see_first() const { if (first == NULL) throw runtime_error("see_first on empty list"); return first->data; } string remove_first() { if (first == NULL) throw runtime_error("remove_first on empty list"); link * old = first; first = first->next; string result = old->data; delete old; return result; } }; int main(int argc, char * argv[]) { int number = 16; if (argc > 1) number = atol(argv[1]); srandomdev(); list a; for (int i = 0; i < number; i += 1) a.add_to_end(random_string(5, 7)); list::enumerator e = a.get_enumerator(); while (e.any_more()) cout << e.get_next() << "\n"; }