#include #include #include using namespace std; #include "llist.h" int main( int argc, char* argv[] ) { if ( argc != 2 ) { cerr << "Usage: " << argv[0] << " outfile\n"; return 1; } ofstream out_str( argv[1] ); if ( !out_str ) { cerr << "Failed to open " << argv[1] << '\n'; return 1; } // Empty initial pointer. Node * int_list_ptr = 0; // After the following, int_list_ptr should point to the first node // in the list and there should be six nodes in the list, // containing, in order, 12, 24, 8, 24, 16, and 35. add_to_back( int_list_ptr, 8 ); add_to_back( int_list_ptr, 24 ); add_to_back( int_list_ptr, 16 ); add_to_back( int_list_ptr, 35 ); add_to_front( int_list_ptr, 24 ); add_to_front( int_list_ptr, 12 ); out_str << "Output (1), after 4 add_to_back and 2 add_to_front calls:" << endl; print_list( int_list_ptr, out_str ); // After the following the list should contain only four nodes, // with the values 12, 8, 16 and 35. remove_each( int_list_ptr, 24 ); out_str << "Output (2), after removing 24:" << endl; print_list( int_list_ptr, out_str ); // After the following the list should still contain the same four // nodes, but in reverse order with the values 35, 16, 8 and 12 reverse_list( int_list_ptr ); out_str << "Output (3), after reverse_list:" << endl; print_list( int_list_ptr, out_str ); // After the following, the output should just be destroy_list( int_list_ptr ); out_str << "Output (4), after destroy_list:" << endl; print_list( int_list_ptr, out_str ); // After the following the list should contain buffalo, chimp, monkey, monkey, zebra Node * string_list_ptr = 0; string s = "monkey"; ordered_insert( string_list_ptr, s ); s = "buffalo"; ordered_insert( string_list_ptr, s ); s = "zebra"; ordered_insert( string_list_ptr, s ); s = "monkey"; ordered_insert( string_list_ptr, s ); s = "chimp"; ordered_insert( string_list_ptr, s ); out_str << "Output (5), after creating an ordered list:" << endl; print_list( string_list_ptr, out_str ); // After the following the resulting list should contain // banana, buffalo, chimp, monkey, monkey, monkey, tiger, zebra Node * second_string_ptr = 0; s = "banana"; ordered_insert( second_string_ptr, s ); s = "monkey"; ordered_insert( second_string_ptr, s ); s = "tiger"; ordered_insert( second_string_ptr, s ); Node * merged_list_ptr = ordered_merge( string_list_ptr, second_string_ptr ); out_str << "Output (6), after merging two ordered lists:" << endl; print_list( merged_list_ptr, out_str ); return 0; }