Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 658 of 719
2K+ Views
Arrays can be passed to a function as an argument. In this program, we will perform to display the elements of the 2 dimensional array by passing it to a function.AlgorithmBegin The 2D array n[][] passed to the function show(). Call function show() function, the array n (n) is traversed using a nested for loop. EndExample Code Live Demo#include using namespace std; void show(int n[4][3]); int main() { int n[4][3] = { {3, 4 ,2}, {9, 5 ,1}, {7, 6, 2}, {4, 8, 1}}; show(n); return 0; } void show(int n[][3]) { cout
348 Views
A dynamic 2D array is basically an array of pointers to arrays. Here is a diagram of a 2D array with dimenation 3 x 4.AlgorithmBegin Declare dimension of the array. Dynamic allocate 2D array a[][] using new. Fill the array with the elements. Print the array. Clear the memory by deleting it. EndExample Code Live Demo#include using namespace std; int main() { int B = 4; int A = 5; int** a = new int*[B]; for(int i = 0; i < B; ++i) a[i] = new int[A]; ... Read More
207 Views
In C++, it is faster to process a sorted array than an unsorted array due to some reasons related to algorithm efficiency and data access patterns. In this article, we see why this is the case and how sorting can improve performance of array processing. First of all, let see an example of processing time of a sorted and unsorted array. Processing Time: Sorted vs Unsorted Array In the example code below, we have used library of C++ STL to measure the time taken to process an unsorted array and a sorted array. The code counts how many ... Read More
3K+ Views
Bit array is used to store true/false or yes/no type of values in very less memory. In this article, we will see how to create and use a bit array in C++. What is Bit Array? Bit array is a special array where each element can hold only 0 or 1. Instead of using a full byte (8 bits) for each boolean value, a bit array stores multiple values using just one bit each. Meaning, in a normal array of bool values, each value takes at least one byte. But in bit array, we store 8 values in one ... Read More
652 Views
In this article, we will learn what is graph structured stack and how to implement it in a C++ program. What is Graph Structured Stack? Graph structured stack is a directed acyclic graph, where each directed path represents a stack. In this types of stack, the flow of execution is not linear like a traditional stack, instead the flow is represented using a graph structure. Each node in the graph can represent a function call or a state, and the edges define possible transitions or calls. This type of stacks are useful in advanced control flow handling like backtracking, ... Read More
2K+ Views
DAG stands for Directed Acyclic Graph. It is a special type of graph where all edges are directed and there are no cyclic connections of edges. In this article, we will discuss how to check whether a graph is a DAG using Kahn’s algorithm (BFS based topological sorting). What is DAG? A DAG is a directed graph with no cycles. That means in this type graph it is not possible to start from any node and follow a sequence of edges such that you will return back to the starting node. DAGs are commonly used in applications like task ... Read More
400 Views
Edge coloring is a method of coloring the edges of a graph, such that no two edges having a common vertex is colored with same color. A line Graph is a special type of graph which help us to assume an edge-coloring problem into a vertex-coloring problem. In other words, using a line graph makes edge coloring easier. In this article, we will discuss how to perform edge coloring of a graph using line graph and greedy coloring approach. What is Line Graph? Line graph is a special graph that is created from another graph. In the line ... Read More
569 Views
Graph coloring is a technique in which, we assign colors to the vertices of a graph such that no two adjacent vertices have same color. Bipartite graph a special kind of graph which is possible to color by just two colors. In this article, we will discuss how to perform graph coloring on a bipartite graph using BFS algorithm. What is Bipartite Graph? Bipartite graph is special graph where you can divide the vertices into two sets, such that no two vertices of the same set are connected. This is why, it's possible to color a bipartite graph by ... Read More
923 Views
There is a big distinction between the suffix and prefix versions of ++.In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression.In the postfix version (i.e., i++), the value of i is incremented, but the value of the expression is the original value of i. So basically it first assigns a value to expression and then increments the variable.Let's look at some code to get a better understanding.Example Code#include using namespace std; int main() ... Read More
3K+ Views
Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled access modifiers: public, private, and protected sections within the class body.The default access for members and classes is private.Example Codeclass Base { public: // public members go here protected: // protected members go here private: ... Read More