AI という名前のクラスの要素を含む優先キューがあります。このキューの要素は、キューの下にある可能性があります (優先度が低くなります)。そのため、選択した要素が得られるまで、いくつかの要素をポップしようとしています。選択した要素を取得したら、一時的に配列に保存したすべての要素をプッシュする予定です。ループがあり、繰り返しごとにキューをさらに下って、ポップした要素が自分の選択であるかどうかを確認します。このようにして、より多くのデータが一時配列にあります。この一時配列からプライオリティ キューにデータをプッシュしようとすると、問題が発生します。優先度の基礎となるコンテナはベクトルであり、デバッグは問題が行 std::push_heap(c.begin(), c.end(), comp); で stl_queue.h にあることを示しています。(c はベクトル)
これは間違った方法である可能性があり、malloc の代わりにコンストラクターを使用し、プライオリティ キューの代わりに std:list を使用する必要があることはわかっていますが、ここで何が起こっているのか教えてもらえますか?
while(count < length_of_queue) // Iterate over all elements of queue
{
A* temp_array = (A *)malloc(count * sizeof(A));;
for (int i = 0;i<count;i++) // remove count number of elements from queue
{
temp_array[i] = priority queue.top();
priority queue.pop(); // free_list is the priority queue
}
A check_element = free_list.top(); // Check if (count+1)th elements satisfies our
// criteria
if (criteria_satisfied)
{
priority_queue.pop();
//freeing the temp_array and pushing back all the elements from temp_array into
// priority_queue like done in the else condition
return check_element;
}
else
{
for (int i = 0;i<count;i++) // Push back all the elements popped until now
{
priority_queue.push(temp_array[i]); // Offending line
}
free (temp_array);
}
count++
}