2002

Grusel++ of the month

Home
Download Source
/******************************************************************************/
/*                                                                            */
/*                                                          FILE: january.cpp */
/*                                                                            */
/*  Ordering a jumble of pairs with a priority_queue                          */
/*  ================================================                          */
/*                                                                            */
/*  Compiled and tested with Visual C++ V6.0                                  */
/*                                                                            */
/*  V1.00   24-JAN-2002   P. Tellenbach   http://www.heimetli.ch/             */
/*                                                                            */
/******************************************************************************/

#include <iostream>
#include <queue>
#include <utility>

int main()
{
   std::priority_queue< std::pair<char,char> > pq ;

   pq.push( std::make_pair('!',' ' ) ) ;
   pq.push( std::make_pair('o','l' ) ) ;
   pq.push( std::make_pair('e','o' ) ) ;
   pq.push( std::make_pair('l',' ' ) ) ;
   pq.push( std::make_pair('o','l' ) ) ;
   pq.push( std::make_pair('l','o' ) ) ;
   pq.push( std::make_pair('!','l' ) ) ;
   pq.push( std::make_pair(' ','!' ) ) ;
   pq.push( std::make_pair('!','d' ) ) ;
   pq.push( std::make_pair('d','r' ) ) ;
   pq.push( std::make_pair('w','H' ) ) ;
   pq.push( std::make_pair('e','w' ) ) ;
   pq.push( std::make_pair('r','e' ) ) ;
   pq.push( std::make_pair(' ','\n') ) ;

   while( std::cout << pq.top().second, pq.pop(), !pq.empty() )
      ;

   return int() ;
}

Update 25. January 2022

This program compiles and runs without any changes.