Пример #1
0
  void process_commands(std::string preface) {
    for (;;) try {
      std::string command = menu_prompt(preface);

      if (command == "v") {
        std::string e = ics::prompt_string(preface+"  Enter element to add");
        std::cout << preface+"  push = " << s.push(e) << std::endl;
      }
      else if (command == "V") {
        StackType s2(prompt_stack(preface));
        std::cout << "  push_all = " << s.push_all(s2) << std::endl;;
      }
      else if (command == "^")
        std::cout << preface+"  pop = " << s.pop() << std::endl;

      else if (command == "x")
        s.clear();

      else if (command == "=") {
        StackType s2(prompt_stack(preface));
        s = s2;
        std::cout << "  s now = " << s << std::endl;
      }

      else if (command == "m")
        std::cout << preface+"  empty = " << s.empty();

      else if (command == "s")
        std::cout << preface+"  size = " << s.size() << std::endl;


      else if (command == "p") {
        std::cout << preface+"  peek = " << s.peek() << std::endl;
      }

      else if (command == "<")
        std::cout << preface+"  << = " << s << std::endl;

      else if (command == "r") {
        std::cout << preface+"  s == s = " << (s == s) << std::endl;
        std::cout << preface+"  s != s = " << (s != s) << std::endl;

        StackType s2(prompt_stack(preface));
        std::cout << preface+"  s = " << s << " ?? s2 = " << s2 << std::endl;
        std::cout << preface+"  s == s2 = " << (s == s2) << std::endl;
        std::cout << preface+"  s != s2 = " << (s != s2) << std::endl;
      }

      else if (command == "lf") {
        std::ifstream in_stack;
        ics::safe_open(in_stack,preface+"  Enter file name to read", "loadstack.txt");
        std::string e;
        while (getline(in_stack,e))
          s.push(e);
        in_stack.close();
      }

      else if (command == "l{")
        s = StackType{"c","b","d","e","a"};


      else if (command == "it")
        process_iterator_commands(s, "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;
    }

  };
    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;
      }

    };
  void process_commands(std::string preface) {
    for (;;) try {
      std::string command = menu_prompt(preface);

      if (command == "i") {
        std::string e = ics::prompt_string(preface+"  Enter element to add");
        std::cout << preface+"  insert = " << s.insert(e) << std::endl;
      }

      else if (command == "I") {
        SetType s2(prompt_set(preface));
        std::cout << "  insert = " << s.insert(s2.abegin(),s2.aend()) << std::endl;;
      }

      else if (command == "e") {
        std::string e = ics::prompt_string(preface+"  Enter element to erase");
        std::cout << preface+"  erase = " << s.erase(e) << std::endl;
      }

      else if (command == "E") {
        SetType s2(prompt_set(preface));
        std::cout << "  erase = " << s.erase(s2.abegin(),s2.aend()) << std::endl;;
      }

      else if (command == "x")
        s.clear();

      else if (command == "R") {
        SetType s2(prompt_set(preface));
        std::cout << "  retain = " << s.retain(s2.abegin(),s2.aend()) << std::endl;
      }

      else if (command == "=") {
        SetType s2(prompt_set(preface));
        s = s2;
        std::cout << "  s now = " << s << std::endl;
      }

      else if (command == "m")
        std::cout << preface+"  empty = " << s.empty();

      else if (command == "s")
        std::cout << preface+"  size = " << s.size() << std::endl;


      else if (command == "c") {
        std::string e = ics::prompt_string(preface+"  Enter element to erase");
        std::cout << preface+"  contains = " << s.contains(e) << std::endl;
      }

      else if (command == "C") {
        SetType s2(prompt_set(preface));
        std::cout << "  contains = " << s.contains(s2.abegin(),s2.aend()) << std::endl;
      }

      else if (command == "<")
        std::cout << preface+"  << = " << s.str() << std::endl;

      else if (command == "r") {
        std::cout << preface+"  s == s = " << (s == s) << std::endl;
        std::cout << preface+"  s != s = " << (s != s) << std::endl;
        std::cout << preface+"  s <= s = " << (s <= s) << std::endl;
        std::cout << preface+"  s <  s = " << (s <  s) << std::endl;
        std::cout << preface+"  s >  s = " << (s >  s) << std::endl;
        std::cout << preface+"  s >= s = " << (s >= s) << std::endl;

        SetType s2(prompt_set(preface));
        std::cout << preface+"  s = " << s << " ?? s2 = " << s2 << std::endl;
        std::cout << preface+"  s == s2 = " << (s == s2) << std::endl;
        std::cout << preface+"  s != s2 = " << (s != s2) << std::endl;
        std::cout << preface+"  s <= s2 = " << (s <= s2) << std::endl;
        std::cout << preface+"  s <  s2 = " << (s <  s2) << std::endl;
        std::cout << preface+"  s >  s2 = " << (s >  s2) << std::endl;
        std::cout << preface+"  s >= s2 = " << (s >= s2) << std::endl;
      }

      else if (command == "l") {
        std::ifstream in_set;
        ics::safe_open(in_set,preface+"  Enter file name to read", "load.txt");
        std::string e;
        while (getline(in_set,e))
          s.insert(e);
        in_set.close();
      }

      else if (command == "it")
        process_iterator_commands(s, "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;
    }

  };