I declared a global struct with the following structure:
typedef struct {
int value;
int index;
}element;
I have a program with k sorted queues, and I put in a heapSort(I am using an array) the minimum from each one. I use the index value in struct to track the element that I want to pop out of the heap. Now, I want to test the program for different number of queues, so I did this:
for (int i = 10;i <= 50;i += 10) {
const int k = i;
element a[k];
}
But I get an error:
Expression must have a constant value
Is there any way I can "trick" that?
std::vector<element> a(k).std::vector<element> a(i);and throw outkentirely. And fyi, if allowed by whatever purpose this is for, the heap operations in<algorithm>will come in very handy and save you a ton of code. If this is for a priority queue, thestd::priority_queueadapter can save you even more effort.