Constructor initialization lists – C++ provides a way of initializing member variables that allows us to initialize member variables when they are created rather than afterwards. This is done through use of an initialization list.
Something() : m_nValue ( 0 ), m_dValue( 0.0 ), m_pnValue( 0 ) // A default constructor
Something(int nValue, double dValue, int *pnValue) : m_nValue ( nValue ), m_dValue( dValue ), m_pnValue( pnValue ) // A specific constructor
Definition : Heap sort is comparison based sorting algorithm based on Binary Heap data structure. It is similar to selection sort where we first find the maximum element and place the maximum element at the end. We repeat the same process for remaining element.
A Binary Heap is a Complete Binary Tree where items are stored in a special order such that value in a parent node is greater(or smaller) than the values in its two children nodes. The former is called as max heap and the latter is called min heap.
Binary Heap is a Complete Binary Tree, it can be easily represented as array and array based representation is space efficient. If the parent node is stored at index I, the left child can be calculated by 2 * I + 1 and right child by 2 * I + 2.
Heap Sort Algorithm for sorting in increasing order: 1. Build a max heap from the input data. 2. At this point, the largest item is stored at the root of the heap. Replace it with the last item of the heap followed by reducing the size of heap by 1. Finally, heapify the root of tree. 3. Repeat above steps until size of heap is greater than 1.
“The only way to do great work is to love what you do" – Steve Jobs