Found 7346 Articles for C++

C++ Program to Implement Min Heap

George John
Updated on 30-Jul-2019 22:30:25

10K+ Views

A Binary Heap is a complete binary tree which is either Min Heap or Max Heap. In a Max Binary Heap, the key at root must be maximum among all keys present in Binary Heap. This property must be recursively true for all nodes in Binary Tree. Min Binary Heap is similar to Min Heap.AlgorithmFor min_heap():Begin    Declare function min_heap(int *a, int m, int n)       Declare j, t of the integer datatype.       Initialize t = a[m].       j = 2 * m;       while (j = a[j]) then     ... Read More

C++ Program to Implement Max Heap

Chandu yadav
Updated on 30-Jul-2019 22:30:25

12K+ Views

A Binary Heap is a complete binary tree which is either Min Heap or Max Heap. In a Max Binary Heap, the key at root must be maximum among all keys present in Binary Heap. This property must be recursively true for all nodes in Binary Tree. Min Binary Heap is similar to MinHeap.AlgorithmFor max_heap:Begin    Declare function max_heap ()       Declare j, t of the integer datatype.       Initialize t = a[m].       j = 2 * m;       while (j a[j]) then             j ... Read More

C++ Program to Implement Binary Heap

George John
Updated on 30-Jul-2019 22:30:25

4K+ Views

A Binary Heap is a complete binary tree which is either Min Heap or Max Heap. In a Max Binary Heap, the key at root must be maximum among all keys present in Binary Heap. This property must be recursively true for all nodes in that Binary Tree. Min Binary Heap is similar to MinHeap.Function descriptions:void BHeap::Insert(int ele): Perform insertion operation to insert element in heap.void BHeap::DeleteMin(): Perform deleteion operation to delete minimum value from heap.int BHeap::ExtractMin(): Perfrom operation to extract minimum value from heap.void BHeap::showHeap(): To show the elements of heap.void BHeap::heapifyup(int in): maintain heap structure in bottom up ... Read More

In C++ What are the differences between a pointer variable and a reference variable?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

269 Views

ReferencesWhen a variable is declared as reference, it becomes an alternative name for an existing variable.SyntaxType &newname = existing name;InitializatioType &pointer; pointer = variable name;PointersPointers are used to store the address of variable.SyntaxType *pointer;InitializationType *pointer; pointer = variable name;The main differences between references and pointers are -References are used to refer an existing variable in another name whereas pointers are used to store address of variable.References cannot have a null value assigned but pointer can.A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.A reference must be initialized on declaration ... Read More

Pointers vs References in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

9K+ Views

PointersPointers are used to store the address of variable.SyntaxType *pointer;InitializationType *pointer; pointer = variable name;ReferencesWhen a variable is declared as reference, it becomes an alternative name for an existing variable.SyntaxType &newname = existing name;InitializationType &pointer; pointer = variable name;The main differences between pointers and references are -References are used to refer an existing variable in another name whereas pointers are used to store address of variable.References cannot have a null value assigned but pointer can.A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.A reference must be initialized on declaration ... Read More

Passing by pointer Vs Passing by Reference in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

3K+ Views

These are simple example of passing by pointer and passing by reference -Passing by pointer Live Demo#include using namespace std; void swap(int* a, int* b) {    int c = *a;    *a= *b;    *b = c; } int main() {    int m = 7, n = 6;    cout

References in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

255 Views

A reference variable is an alias, that is, another name for an already existing variable. Once a reference is initialized with a variable, either the variable name or the reference name may be used to refer to the variable.References vs PointersReferences are often confused with pointers but three major differences between references and pointers are −You cannot have NULL references. You must always be able to assume that a reference is connected to a legitimate piece of storage.Once a reference is initialized to an object, it cannot be changed to refer to another object. Pointers can be pointed to another ... Read More

Execute both if and else statements in C/C++ simultaneously

Anvi Jain
Updated on 30-Jul-2019 22:30:25

286 Views

In this section, we will see how to execute the if and else section simultaneously in a C or C++ code. This solution is a little bit tricky.When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another.Example Code#include using namespace std; int main() {    int x = 10;    if(x > 5) {       lebel_1: cout

How many levels of pointers can we have in C/C++?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

128 Views

Actually, C programs one or two static levels of pointers are common. Triple indirection is rare. But infinite is very common. Infinite pointer indirection can be achieved with the help of a struct.struct list { struct list *next; ... } lst; lst->next->next->next->...->nextand in this way we can implement multiple pointer indirection.There is another alternative notation as shown below– *(*(..(*(*(*lst).next).next).next...).next).next

How does #include work in C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

The is a header file. This file includes all standard library. Sometimes in some coding contests, when we have to save time while solving, then using this header file is helpful.In software engineering approach we should reduce the minimize the include. Using this header file, it will include lots of files, sometimes that may not be required in the program. So it may increase the compile time and program size. Some of the big disadvantages of this header file is listed below −This is not a standard header file of GNU C++ library. So some compiler may fail ... Read More

Advertisements