Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Priority Queues

How can  I turn a vector into a min-heap, then into a priority queue, Can I have an example?
0
MissProgrammer
Asked:
MissProgrammer
  • 3
  • 3
1 Solution
 
jkrCommented:
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
 
MissProgrammerAuthor Commented:
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
 
jkrCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
MissProgrammerAuthor Commented:
Will it be the lowest value be on top of the priority queue or do I need some type of compare function?
0
 
jkrCommented:
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
 
MissProgrammerAuthor Commented:
Thanks that really helped
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.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now