Solved

Priority Queues

Posted on 2006-11-01
6
414 Views
Last Modified: 2011-09-20
How can  I turn a vector into a min-heap, then into a priority queue, Can I have an example?
0
Comment
Question by:MissProgrammer
  • 3
  • 3
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 17851235
What do you mean by a 'min-heap'? In general, you can do that like

vector<int> v;

//... fill vector

priority_queue<int> q(v.begin(),v.end());

See also http://www.sgi.com/tech/stl/priority_queue.html
0
 

Author Comment

by:MissProgrammer
ID: 17852787
Min-heap means that I have to store the vector in a heap that has the lowest number first,  I want to execute the character with the lowest time in my programm
0
 
LVL 86

Expert Comment

by:jkr
ID: 17852915
Then sort (http://www.sgi.com/tech/stl/sort.html) the vector first:

vector<int> v;

//... fill vector

sort(v.begin(),v.size());

priority_queue<int> q(v.begin(),v.end());
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:MissProgrammer
ID: 17852938
Will it be the lowest value be on top of the priority queue or do I need some type of compare function?
0
 
LVL 86

Expert Comment

by:jkr
ID: 17853105
Yes, see check the 'sort' example on http://www.sgi.com/tech/stl/sort.html

int A[] = {1, 4, 2, 8, 5, 7};
const int N = sizeof(A) / sizeof(int);
sort(A, A + N);
copy(A, A + N, ostream_iterator<int>(cout, " "));
// The output is " 1 2 4 5 7 8".
0
 

Author Comment

by:MissProgrammer
ID: 17853176
Thanks that really helped
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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

831 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