⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soln10_2.cpp

📁 Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008 With sourcecode
💻 CPP
字号:
// Soln 10_2.cpp
// The contents of a priority_queue container are automatically in ascending
// sequence if you create the container so it uses the greater<T> predicate
// to order the contents.
// Remember a priority_queue container is created through a container adapter
// so no iterators are available for it.
#include <iostream>
#include <iterator>
#include <queue>              
#include <vector>              

using std::cout;
using std::endl;
using std::cin;
using std::priority_queue;
using std::queue;
using std::vector;
using std::greater;
using std::istream_iterator;
using std::ostream_iterator;
using std::back_inserter;

int main()
{
  priority_queue<char, vector<char>, greater<char>> characters;
  cout << "Enter characters then Enter followed by Ctrl+Z to end:" << endl;

  istream_iterator<char> charsInput(cin), charsEnd;   // Input stream iterator for character input
  
  while(charsInput != charsEnd)
    characters.push(*charsInput++);

  // Output the contents of the container
  cout << "You entered the following characters:" << endl;
  while(!characters.empty())
  {
    cout << characters.top() << ' ';
    characters.pop();
  }

  cout << endl;

   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -