Server Side Programming Articles - Page 2308 of 2651

Sorting in C++

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

2K+ Views

In this section we will see how to perform sorting algorithm in C++. A sorted array is an array in which each of the elements are sorted in some order such as numerical, alphabetical etc. There are many algorithms to sort a numerical array such as bubble sort, insertion sort, selection sort, merge sort, quick sort, heap sort etc. More details about sorting the array using selection sort are given below.The selection sort is a sorting method that yields a sorted array. It does so by repeatedly finding the smallest element in the array and interchanging it with the element ... Read More

Can namespaces be nested in C++?

Revathi Satya Kondra
Updated on 21-Apr-2025 19:24:03

294 Views

Yes, the namespace can be nested in C++. We can define one namespace inside another namespace. This makes it easier for developers to design a more structured and hierarchical format for their code. Syntax The following is the syntax as below : namespace namespace_name1 { // code declarations namespace namespace_name2 { // code declarations } } You can access members of a nested namespace by using resolution operators as follows: // to access members of namespace_name2 ... Read More

Namespace in C++

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

247 Views

Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother’s or father’s name, etc.Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function ... Read More

C++ default constructor

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

245 Views

A class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.Following example explains the concept of constructor −Example Live Demo#include using namespace std; class Line {    public:       void setLength( double len );       double getLength( void );       Line(); // This is the constructor       private:       double length; }; // Member functions definitions including constructor Line::Line(void) {    cout

C++ Program to Implement Min Heap

Nishu Kumari
Updated on 03-Mar-2025 13:16:55

12K+ Views

In this article, we will write a C++ program that implements a Min Heap. A Min Heap is a binary tree where the value of each node is less than or equal to the values of its children. We will explain how to create a Min Heap using arrays and implement operations like insertion and deletion. The article will cover the following topics: What is a Heap? Types of Heap Representing a Heap What is a Min Heap? What ... Read More

C++ Program to Implement Max Heap

Chandu yadav
Updated on 07-Mar-2025 15:35:32

14K+ Views

In this article, we will write a C++ program that implements a Max Heap. A Max Heap is a binary tree where the value of each node is greater than or equal to the values of its children. We will explain how to create a Max Heap using arrays and implement operations like insertion and deletion. The article will cover the following topics: What is a Heap? What is Max Heap? What is Heapify? Max Heap Implementation Deletion from ... 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

454 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++

Revathi Satya Kondra
Updated on 21-Apr-2025 19:23:35

9K+ Views

In C++, both pointers and references are used to access and manipulate memory. But they behave differently. This guide explains each with simple words and examples. We understand the topic by learning how each is declared, used, and what differences exist between them. What are C++ Pointers? The pointers are used to store the address of a variable. We can change what they pointing to, and also can assign NULL to them. A pointer is similar to a signpost that contains the memory address of another variable, and you can directly access or change the variable by its address. Syntax ... Read More

Passing by pointer Vs Passing by Reference in C++

Revathi Satya Kondra
Updated on 17-Apr-2025 18:40:27

3K+ Views

In C++, If we want to pass arguments to functions we can either pass the actual value, a pointer to the value, or a reference to the value. This concept becomes crucial when we want a function to modify the original variable. So, if we pass parameter to a function either by pass by pointer or pass by reference it will produce the same result. Only difference is that References are used to refer an existing variable in another name whereas pointers are used to store address of variable. It is safe to use reference because it cannot be NULL. ... Read More

Advertisements