Found 7346 Articles for C++

C++ Program to Implement Bit Array

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

2K+ Views

This is a C++ program to implement Bit Array. A Bit Array is an array data structures that compactly stores data. It is basically used to implement a simple data structure.AlgorithmFunctions and pseudocodes:Begin    Function getBit(int val, int pos)    singleBit->b = 0    if(pos == 0)       singleBit->b = val & 1    else       singleBit->b = ( val & (1 > pos       return singleBit    Function setBit(BitArr *bt, B *bit, int pos)       bt->bVal[pos] = bit       return bt    Function getVal(BitArr *bArray)    initialize val = ... Read More

C++ Program to Implement Graph Structured Stack

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

410 Views

In this C++ program we implement Graph Structured Stack.AlgorithmBegin    Function graphStructuredStack(int **adjMat, int s, int bNode):    Take an array adjMat, source s and bottom node bNode    initialize stackFound = false    for sVertex = 1 to noOfNodes       for dVertex = 1 to noOfNodes          this->adjMat[sVertex][dVertex] = adjMat[sVertex][dVertex]       Done    Done    Push source into mystack.    while (!mystack.empty())       element = mystack.top()       Initialize destination, d=1       while (d adjMat[element][d] == 1)             Push destination into mystack ... Read More

C++ Program to Check Whether Graph is DAG

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

A directed acyclic graph (DAG) is a graph that is directed and without cycles connecting the other edges. The edges of this graph go one way. This is a C++ program to check whether the graph is DAG.AlgorithmBegin Function checkDAG(int n):    intialize count = 0    intialize size = n - 1    for i = 0 to n-1       if (count == size)          return 1       done       if (arr[i].ptr == NULL)          increment count          for j = 0 to n-1 ... Read More

C++ Program to Perform Edge Coloring to the Line Graph of an Input Graph

Nitya Raut
Updated on 30-Jul-2019 22:30:25

248 Views

The line graph of an undirected graph G is another graph L(G) that represents the adjacencies between edges of G. In this program, we Perform Edge Coloring to the Line Graph of an Input Graph.AlgorithmBegin    Take the input of the number of vertices ‘n’ and number of edges ‘e’.    Take the input of ‘n’ vertex pairs for the ‘e’ edges in the graph in ed[][].    Function GenLineGraph():       Construct a line graph in LineEd[][].       To construct line graph, for each edge in the given graph, connect it    to its adjacent edge ... Read More

C++ Program to Perform Graph Coloring on Bipartite Graphs

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

347 Views

A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e.; vertices in a set are colored with the same color. In this program we take a bipartite graph as input and outputs colors of each vertex after coloring the vertices.AlgorithmBegin BFS algorithm is used to traverse all the vertices. Take a vertex and colour it yellow. Colour all its neighbour vertices as blue. Colour the next level vertices as yellow and so, until all vertices are coloured. End.Example Code#include using ... Read More

Is there a performance difference between i++ and ++i in C++?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

751 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

Difference between private, public, and protected inheritance in C++

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

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

Difference between 'struct' and 'typedef struct' in C++ program?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

5K+ Views

Basically struct is used to define a structure. But when we want to use it we have to use the struct keyword in C. If we use the typedef keyword, then a new name, we can use the struct by that name, without writing the struct keyword.In C++, there is no difference between 'struct' and 'typedef struct' because, in C++, all struct/union/enum/class declarations act like they are implicitly typedef'ed, as long as the name is not hidden by another declaration with the same name.Though there is one subtle difference that typedefs cannot be forward declared. So for the typedef option, ... Read More

Regular cast vs. static_cast vs. dynamic_cast in C++ program

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

524 Views

static_cast − This is used for the normal/ordinary type conversion. This is also the cast responsible for implicit type coersion and can also be called explicitly. You should use it in cases like converting float to int, char to int, etc.dynamic_cast − This cast is used for handling polymorphism. You only need to use it when you're casting to a derived class. This is exclusively to be used in inheritance when you cast from base class to derived class.Regular Cast − This is the most powerful cast available in C++ as it combines const_cast, static_cast and reinterpret_cast. but it's also ... Read More

What does int argc, char *argv[] mean in C++?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

655 Views

The argc stands for argument count and argv stands for argument values. These are variables passed to main function when it starts executing. When we run a program we can give arguments to that program like:$ ./a.out helloHere hello is an argument to the executable. This can be accessed in your program.Example Code#include using namespace std; int main(int argc, char** argv) {    cout

Advertisements