void load(PriorityQueueType& q, std::string values) { std::string* v = new std::string[values.size()]; for (unsigned i=0; i<values.size(); ++i) v[i] = values[i]; for (unsigned i=0; i<values.size(); ++i) q.enqueue(v[i]); delete[] v; }
void process_commands(std::string preface) { for (;;) try { std::string command = menu_prompt(preface); if (command == "e") { std::string e = ics::prompt_string(preface+" Enter element to add"); std::cout << preface+" enqueue = " << q.enqueue(e) << std::endl; } else if (command == "E") { PriorityQueueType q2(prompt_queue(preface)); std::cout << " dequeue = " << q.enqueue_all(q2) << std::endl;; } else if (command == "d") std::cout << preface+" dequeue = " << q.dequeue() << std::endl; else if (command == "x") q.clear(); else if (command == "=") { PriorityQueueType q2(prompt_queue(preface)); q = q2; std::cout << " s now = " << q << std::endl; } else if (command == "m") std::cout << preface+" empty = " << q.empty(); else if (command == "s") std::cout << preface+" size = " << q.size() << std::endl; else if (command == "p") { std::cout << preface+" peek = " << q.peek() << std::endl; } else if (command == "<") std::cout << preface+" << = " << q << std::endl; else if (command == "r") { std::cout << preface+" q == q = " << (q == q) << std::endl; std::cout << preface+" q != q = " << (q != q) << std::endl; PriorityQueueType q2(prompt_queue(preface)); std::cout << preface+" q = " << q << " ?? q2 = " << q2 << std::endl; std::cout << preface+" q == q2 = " << (q == q2) << std::endl; std::cout << preface+" q != q2 = " << (q != q2) << std::endl; } else if (command == "lf") { std::ifstream in_queue; ics::safe_open(in_queue,preface+" Enter file name to read", "loadpq.txt"); std::string e; while (getline(in_queue,e)) q.enqueue(e); in_queue.close(); } else if (command == "l{") { q = PriorityQueueType({"c","b","d","e","a"}); } else if (command == "it") process_iterator_commands(q, "it: "+preface); else if (command == "q") break; else std::cout << preface+"\""+command+"\" is unknown command" << std::endl; } catch (ics::IcsError& e) { std::cout << preface+" " << e.what() << std::endl; } };