2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-10-31 01:25:08 +00:00
|
|
|
use std::collections::BinaryHeap;
|
2014-10-03 04:59:32 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn make_pq() -> BinaryHeap<isize> {
|
2015-12-03 01:07:29 +00:00
|
|
|
BinaryHeap::from(vec![1,2,3])
|
2014-10-03 04:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
let mut pq = make_pq();
|
2015-01-25 21:05:03 +00:00
|
|
|
let mut sum = 0;
|
2014-10-03 04:59:32 +00:00
|
|
|
while let Some(x) = pq.pop() {
|
|
|
|
sum += x;
|
|
|
|
}
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(sum, 6);
|
2014-10-03 04:59:32 +00:00
|
|
|
|
|
|
|
pq = make_pq();
|
|
|
|
sum = 0;
|
|
|
|
'a: while let Some(x) = pq.pop() {
|
|
|
|
sum += x;
|
|
|
|
if x == 2 {
|
|
|
|
break 'a;
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(sum, 5);
|
2014-10-03 04:59:32 +00:00
|
|
|
|
|
|
|
pq = make_pq();
|
|
|
|
sum = 0;
|
2018-08-31 13:14:09 +00:00
|
|
|
'a2: while let Some(x) = pq.pop() {
|
2014-10-03 04:59:32 +00:00
|
|
|
if x == 3 {
|
2018-08-31 13:14:09 +00:00
|
|
|
continue 'a2;
|
2014-10-03 04:59:32 +00:00
|
|
|
}
|
|
|
|
sum += x;
|
|
|
|
}
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(sum, 3);
|
2014-10-03 04:59:32 +00:00
|
|
|
|
|
|
|
let mut pq1 = make_pq();
|
|
|
|
sum = 0;
|
|
|
|
while let Some(x) = pq1.pop() {
|
|
|
|
let mut pq2 = make_pq();
|
|
|
|
while let Some(y) = pq2.pop() {
|
|
|
|
sum += x * y;
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 21:05:03 +00:00
|
|
|
assert_eq!(sum, 6 + 12 + 18);
|
2014-10-03 04:59:32 +00:00
|
|
|
}
|