我在向量中有一个队列循环,我需要在队列循环中搜索以找到最小索引队列以及最大大小队列。
我正在使用以下代码
int min_index = 0;
int max_size = -1;
std::size_t size = q.size();
for( i=0; i<size; i++){ //accessing loop of queues
if(q[min_index].size() > q[i].size())
min_index = i; // Now q[min_index] is min_index is the minimum size queue
if(q[i].size() > max_size)
max_size = q[i].size(); // maximum size queue
}
我有点怀疑是否像下面的代码一样使用{}
for eachif statement
int min_index = 0;
int max_size = -1;
std::size_t size = q.size();
for( i=0; i<size; i++){ //accessing loop of queues
if(q[min_index].size() > q[i].size()){
min_index = i; // Now q[min_index] is the shortest queue
}
if(q[i].size() > max_size){
max_size = q[i].size(); // longest queue
}
}
哪一个是正确的,有和没有的有什么区别{}
。对不起,如果这是一个愚蠢的问题。我是编程新手。