Category Archives: C++

How to implement Min Heap using STL?

In C++ STL, there is priority_queue that can directly be used to implement Max Heap. See below example. Output : 30 20 10 5 1 Since elements are printed in descending order, we have a max heap by default.   How to implement Min Heap? priority_queue supports a constructor that requires two extra arguments to… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.
Category: C++

Vector : Sequence Containers – The C++ Standard Template Library (STL) – Set 3

Click here for Set 1 and Set 2 of Vectors.   Vector – upper_bound and lower_bound   Iterator lower_bound (Iterator first, Iterator last, const val) Iterator upper_bound (Iterator first, Iterator last, const val)   lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.
Category: C++

Scope resolution operator in C++

In C++, scope resolution operator is ::. It is used for following purposes. 1) To access a global variable when there is a local variable with same name: Output: Value of global x is 0 Value of local x is 10 2) To define a function outside a class. Output: fun() called 3) To access… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.
Category: C++

C++ program to print unique words in a file

Write a function that takes a file name as argument and prints all unique words in it. We strongly recommend you to minimize your browser and try this yourself first The idea is to use map in STL to keep track of words already occurred. Output: code practice qa quiz Thanks to Utkarsh for suggesting… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.
Category: C++

Commonly Asked C++ Interview Questions | Set 2

  Q. Major Differences between JAVA and C++  There are lot of differences, some of the major differences are: Java has automatic garbage collection whereas C++ has destructors , which are automatically invoked when the object is destroyed. Java does not support pointers, templates, unions, operator overloading, structures etc. C++ has no in built support for threads,whereas in… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.
Category: C++

Counting Inversions using Set in C++ STL

Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Two elements a[i] and a[j] form an inversion if a[i] > a[j] and i <… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.
Category: C++