Solved

Event simulation using priority queues

Posted on 2006-11-01
4
234 Views
Last Modified: 2010-04-01
Im writing a program which deals with a character going to a wizard cave at a certain time.  In a text file contains the characters' arrival time and request time.  I need to put  the times in a vector then into a priority queue, where the lowest time is the highest priority.  Can I have any help or guidance to start on project.  What type of classes do I need and what do I need to contain in these classes?
0
Comment
Question by:MissProgrammer
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17855783
std::priority_queue
0
 

Author Comment

by:MissProgrammer
ID: 17855794
What does that suppose to mean??
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17856364
#include <iostream>
//for example
#include <iostream>
#include <list>
#include <queue>
int main(){
  std::priority_queue<int, std::vector<int>, std::greater<int> > intPQueue;
  intPQueue.push(2);
  intPQueue.push(7);
  intPQueue.push(1);
  intPQueue.push(8);
  std::cout << "values removed from priority queue" << std::endl;
  int size=intPQueue.size();
  for( int i=0; i<size; i++ ){
    std::cout << intPQueue.top() << std::endl;
    intPQueue.pop();
  }
}
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Would like to move button in a function 3 77
C++ question 3 65
How to convert MFC::CString to UTF8 wchar_t* 10 211
Dialogbox API leak? 18 96
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question