Tag archive for C++

Using heap is C++

2 minute read

Heap is a very important and widely used in any programing language. Unlike queue and stack, there are no dedicated class for heap in C++. However, there are some functions that let you work with heap in C++. This post will discuss about these functions and how should we use them. 1. make_heap() template <class RandomAccessIterator, class Compare> void make_heap (RandomAccessIterator first, RandomAccessIterator last, Compare comp ); A heap in C++ is a max-heap by default, the default comparator is operator<, if you want a min_heap change the comp arguments to something like std::greater<int>().the eleme...

Notes on C++ class constructor and destructor

5 minute read

In this posts, I will list some notes that I think they worth to be reminded when mentioning about classes’ declaration, constructor, and destructor. 1. In-class member function is inline function If you define a method member inside the class declaration such as class People { string first_name() {return _fname;} string last_name(); } string People::last_name {return _lname;} Then first_name() function will be an inline function by default while the function last_name() is not. Remember the good and the bad of an inline function. On the good side, an inline function can remove the overhead of the function calling mechanism, thus, i...

Back to top ↑