【发布时间】:2013-01-16 09:40:07
【问题描述】:
我有一个队列循环(n 队列数),我想搜索所有大小的队列并找到最小大小的队列。
我只是想到了一个逻辑
std::queue<int> q;
/* fill queue ... */
int min_value = INT_MAX;
std::size_t size = q.size();
for( q=2; q=n; q++){ // from the second queue to the end queue
if
min_value=min.size() > q.size()?
q.size()=min_value
这个逻辑是否正确,我不确定,谁能帮帮我!
已编辑:我试图弄清楚
std::queue<int> q;
/* fill queue ... */
int min_value = INT_MAX;
std::size_t size = q.size();
for( q=0; q<n; q++){ // given loop of queues
if
(q.size()<min_value) // q.size() is compared with the min_value (limits MAX)
min_value=q.size(); // any value of my q.size() which is less than INT_MAX will initially be declared the minimum value. On subsequent iterations this value is refined -- if a smaller value is found that's used for future iterations. at the end of loop, i will get the least value.
这个逻辑正确吗?
【问题讨论】:
-
很难说你的逻辑是否正确,因为有很多语法错误。请发布至少可以编译的内容。
-
哦,是的,但是你能说一下如何比较每个队列的大小并获得最小值的逻辑,然后我可以用语法锻炼
-
@interjay architects.dzone.com/articles/algorithm-week-minimum-and 这个逻辑能解决吗