Skip to content

Commit cc8f337

Browse files
committed
Finish heap functions.
1 parent 384d658 commit cc8f337

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

STL_examples.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,24 +822,87 @@ TEST(make_heap, ExampleOne) {
822822
}
823823

824824
TEST(push_heap, ExampleOne) {
825+
// Constructs a max heap.
826+
std::vector<int> v{1,2,3,4,5,6,5,4};
827+
std::make_heap(v.begin(), v.end());
825828

829+
v.push_back(9);
830+
std::push_heap(v.begin(), v.end());
831+
832+
const std::vector<int> expected_heap{9,6,5,5,2,3,1,4,4};
833+
EXPECT_EQ(v, expected_heap);
826834
}
827835

828836
TEST(pop_heap, ExampleOne) {
837+
// Removes the largest element.
838+
std::vector<int> v{1,2,3,4,5,6,5,4};
839+
std::make_heap(v.begin(), v.end());
840+
841+
std::pop_heap(v.begin(), v.end());
829842

843+
const std::vector<int> expected_heap{5,4,5,4,2,3,1,6};
844+
EXPECT_EQ(v, expected_heap);
830845
}
831846

832847
TEST(sort_heap, ExampleOne) {
848+
// Converts the max heap into a sorted range in ascending order.
849+
std::vector<int> v{1,2,3,4,5,6,5,4};
850+
std::make_heap(v.begin(), v.end());
833851

852+
const std::vector<int> expected_heap{6,5,5,4,2,3,1,4};
853+
EXPECT_EQ(v, expected_heap);
854+
855+
std::sort_heap(v.begin(), v.end());
856+
const std::vector<int> sorted_v{1,2,3,4,4,5,5,6};
857+
EXPECT_EQ(v, sorted_v);
834858
}
835859

836860
// Minimum, maximum operations.
861+
TEST(max, ExampleOne) {
862+
863+
}
864+
865+
TEST(max_element, ExampleOne) {
866+
867+
}
868+
869+
TEST(min, ExampleOne) {
870+
871+
}
872+
873+
TEST(min_element, ExampleOne) {
874+
875+
}
876+
877+
TEST(minmax, ExampleOne) {
878+
879+
}
880+
881+
TEST(minmax_element, ExampleOne) {
882+
883+
}
884+
885+
TEST(clamp, ExampleOne) {
886+
887+
}
837888

838889
// Comparison operations.
890+
TEST(equal, ExampleOne) {}
891+
892+
TEST(lexicographical_compare, ExampleOne) {}
893+
894+
TEST(lexicographical_compare_three_way, ExampleOne) {}
839895

840896
// Permutation operations.
897+
TEST(is_permutation, ExampleOne) {}
898+
899+
TEST(next_permutation, ExampleOne) {}
900+
901+
TEST(prev_permutation, ExampleOne) {}
841902

842903
// Numeric operations.
843904

844905
// Operations on uninitialized memory.
845906

907+
// C library.
908+

0 commit comments

Comments
 (0)