株式会社エス・スリー・フォー

STL Samples : <queue>

キュー

classqueue

優先順位キュー

classpriority_queue

source

#include <iostream>
#include <queue>

using namespace std;

void std_queue() {
  cout << "queue" << endl;
  queue<int> que;

  cout << "enqueue... ";
  for ( int i = 0; i < 5; i++ ) {
    que.push(i);
    cout << i << ' ';
  }
  cout << endl << "deque... ";
  while ( !que.empty() ) {
    cout << que.front() << ' ';
    que.pop();
  }
  cout << endl;
}

void std_priority_queue() {
  cout << "priority_queue" << endl;
  priority_queue<int> pque;
  int input[] = { 1,7,6,4,3,2,5 };

  cout << "enqueue... ";
  for ( int i = 0; i < 7; i++ ) {
    pque.push(input[i]);
    cout << input[i] << ' ';
  }
  cout << endl << "deque... ";
  while ( !pque.empty() ) {
    cout << pque.top() << ' ';
    pque.pop();
  }
  cout << endl;
}