Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 队列的最小值_C++_Struct_Queue - Fatal编程技术网

C++ 队列的最小值

C++ 队列的最小值,c++,struct,queue,C++,Struct,Queue,我有这个密码 std::queue<int> q; /* fill queue ... */ int min_value = INT_MAX; std::size_t size = q.size(); while (size-- > 0) { int x = q.front(); q.pop(); q.push(x); if (x < min_value) min_value = x; } std::队列q; /*填

我有这个密码

   std::queue<int> q;
/* fill queue ... */
int min_value = INT_MAX;
std::size_t size = q.size();
while (size-- > 0) {
    int x = q.front();
    q.pop();
    q.push(x);
    if (x < min_value)
        min_value = x;
}
std::队列q;
/*填充队列*/
int最小值=int最大值;
std::size_t size=q.size();
而(大小-->0){
int x=q.front();
q、 pop();
q、 推(x);
如果(x<最小值)
最小值=x;
}
这段代码将给出队列的最小大小(我猜),但不知道如何? 我们设置int min_value=int_MAX,但MAX是整数的上限?那么x
有人能解释一下这个代码流吗?

好的,队列中任何小于INT_MAX的值最初都会被声明为最小值。在随后的迭代中,这个值会被细化——如果找到一个较小的值用于未来的迭代。它会稍微起作用。min_value=INT_MAX只是为了确保它在第一次迭代时进入x