Solved

Event simulation using priority queues

Posted on 2006-11-01
4
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 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