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