void part_two_describe() { cout<<"******************************************"<<endl; cout<<"* 第二章 C++ STL泛型编程 *"<<endl; cout<<"******************************************"<<endl; cout<<"*(1) 一个简单的测试案例 *"<<endl; cout<<"*(2) vector向量容器 *"<<endl; cout<<"*(3) string基本字符系列容器 *"<<endl; cout<<"*(4) set集合容器 *"<<endl; cout<<"*(5) mutiset多种集合容器 *"<<endl; cout<<"*(6) map映照容器 *"<<endl; cout<<"*(7) mutimap多重映照容器 *"<<endl; cout<<"*(8) deque双端队列容器 *"<<endl; cout<<"*(9) list双向链表容器 *"<<endl; cout<<"*(10)bitset位集合容器 *"<<endl; cout<<"*(11)stack堆栈容器 *"<<endl; cout<<"*(12)queue队列容器 *"<<endl; cout<<"*(13)priority_queue优先队列容器 *"<<endl; cout<<"******************************************"<<endl; cout<<"请输入对应的编号进入相应的题目(返回上级输入0):"<<endl; int num; cin>>num; while(num!=0&&num!=1&&num!=2&&num!=3&&num!=4&&num!=5&&num!=6&&num!=7&&num!=8&&num!=9&&num!=10&&num!=11&&num!=12&&num!=13){ cout<<"编号不存在"<<endl; cout<<"请输入对应的编号进入相应的题目(返回上级输入0):"<<endl; cin>>num; } switch(num){ case 0:total_describe();break; case 1:test();break; case 2:vector_test();break; case 3:string_test();break; case 4:set_test();break; case 5:multiset_test();break; case 6:map_test();break; case 7:multimap_test();break; case 8:deque_test();break; case 9:list_test();break; case 10:bitset_test();break; case 11:stack_test();break; case 12:queue_test();break; case 13:priority_queue_test();break; } }
int main(int argc, char* argv[]) { // timing mechanism clock_t start, before_operation, after_operation, end; start = clock(); // parse the command line arguments if (argc != 5 && argc != 7) { std::cerr << "Error: wrong number of arguments." << std::endl; usage(); } std::string data_structure = argv[1]; std::string operation = argv[2]; std::string input = argv[3]; int input_count = -1; int string_length = -1; std::string output_file; if (input == "random") { assert (argc == 7); input_count = atoi(argv[4]); string_length = atoi(argv[5]); output_file = argv[6]; } else { assert (argc == 5); output_file = argv[4]; } // load the data into a heap-allocated, C-style array std::string *input_data; load_data(input,input_data,input_count,string_length); // prepare space for the answer (at most the same size as the input!) std::string *output_data = new std::string[input_count]; int output_count; // mark the time before we start before_operation = clock(); // perform the operation if (data_structure == "vector") vector_test(input_data,input_count,operation,output_data,output_count); else if (data_structure == "list") list_test(input_data,input_count,operation,output_data,output_count); else if (data_structure == "bst") // STL set or map bst_test(input_data,input_count,operation,output_data,output_count); else if (data_structure == "priority_queue") priority_queue_test(input_data,input_count,operation,output_data,output_count); else if (data_structure == "hash_table") // STL unordered_set or unordered_map hash_table_test(input_data,input_count,operation,output_data,output_count); else { std::cerr << "Error: unknown data structure: " << data_structure << std::endl; usage(); exit(0); } // mark the time once we are done after_operation = clock(); // output the data std::ofstream ostr(output_file.c_str()); for (int i = 0; i < output_count; i++) { ostr << output_data[i] << std::endl; } // cleanup delete [] input_data; delete [] output_data; // print statistics end = clock(); double load_time = double(before_operation-start)/CLOCKS_PER_SEC; double operation_time = double(after_operation-before_operation)/CLOCKS_PER_SEC; double output_time = double(end-after_operation)/CLOCKS_PER_SEC; std::cout << "load time: " << load_time << std::endl; std::cout << "operation time: " << operation_time << std::endl; std::cout << "output time: " << output_time << std::endl; std::cout << "input/output ratio: " << input_count << ":" << output_count << std::endl; return 0; }