Skip to content

Commit 384d658

Browse files
committed
begin heap functions.
1 parent 7e5c0b0 commit 384d658

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

STL_examples.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,30 @@ TEST(set_union, ExampleTwoWithDuplicates) {
794794

795795
// Heap operations.
796796
TEST(is_heap, ExampleOne) {
797-
797+
// Checks if the elements in the range are a max heap.
798+
const std::vector<int> v{9, 5, 4, 1, 1, 3};
799+
const bool v_is_heap = std::is_heap(v.cbegin(), v.cend());
800+
EXPECT_TRUE(v_is_heap);
798801
}
799802

800803
TEST(is_heap_until, ExampleOne) {
804+
// Finds largest subsequence in the range that make a max heap.
805+
const std::vector<int> v1{9, 5, 4, 1, 1, 3};
806+
const auto iterator = std::is_heap_until(v1.cbegin(), v1.cend());
807+
EXPECT_EQ(iterator, v1.cend());
801808

809+
const std::vector<int> v2{9, 5, 4, 1, 1, 3, 2, 6};
810+
const auto iterator2 = std::is_heap_until(v2.cbegin(), v2.cend());
811+
EXPECT_EQ(iterator2, v2.cend() - 1);
802812
}
803813

804814
TEST(make_heap, ExampleOne) {
815+
// Constructs a max heap.
816+
std::vector<int> v{1,2,3,4,5,6,5,4};
817+
std::make_heap(v.begin(), v.end());
818+
819+
const std::vector<int> expected_heap{6,5,5,4,2,3,1,4};
820+
EXPECT_EQ(v, expected_heap);
805821

806822
}
807823

0 commit comments

Comments
 (0)