C++ Articles - Page 624 of 717

Difference between C structures and C++ structures

Akansha Kumari
Updated on 11-Jun-2025 17:54:19

4K+ Views

A structures (or struct) is a user-defined data type, which is used to group and store variables of different data types inside a single name. But in C, structures can store only data members whereas C++ can store member functions, constructors, destructors, and even inheritance which is similar to classes in C++, but the only difference between struct and classes is that struct members are public by default. In this following article we will see how structure differs in both C and C++ in detail. Structures in C The structures in C is a user-defined data type, which is used ... Read More

Structure Sorting in C++

Akansha Kumari
Updated on 09-Jun-2025 19:27:25

2K+ Views

A structure in C++ is a user-defined data type, which is used to group and store variables of different data types under a single name. In this article we will see how to sort an array of structures using conditions on member variables. For this we will be using the sort() function which is defined under header file. Syntax Here is the following syntax of sort() function. sort(start_index, end_index, comparison_function); start_index is an iterator (or pointer) to the first element of the array of structures.end_index is an iterator (or pointer) to one past the last element (means last_index + ... Read More

Macros and Preprocessors in C

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

3K+ Views

The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives −Sr.NoDirectives & Descriptions1#defineSubstitutes a preprocessor macro.2#includeInserts a particular header from another ... Read More

enum vs. const vs. #define in C/C++

Akansha Kumari
Updated on 16-Jun-2025 17:23:14

825 Views

The #define, const, and Enum are all used for declaring constant values, but their behaviours and use cases differ. The #define is a preprocessor directive, which is used to define a macro (it is a string or name, in which you can assign a constant value), whereas const is a keyword with which you can declare a variable with a constant value. Whereas, an Enum is a special user-defined data type that represents a group of constants. In the following article, we will learn about all three in detail. Enumeration (Enum) An Enumeration (or Enum) is a user-defined data type ... Read More

How to write a short literal in C++?

Akansha Kumari
Updated on 15-Jul-2025 17:35:04

1K+ Views

In the following article, we will learn about short literals in C++. In both C and C++, different data types have different literals. A literal is a fixed constant value, which is assigned to the variables of different data types. For example, here is a list of different data types with their literals. Datatypes Literals ... Read More

C++ Program to Perform Edge Coloring on Complete Graph

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

373 Views

A complete graph is a graph which has a connecting edge between any pair of vertices. This is a C++ Program to Perform Edge Coloring on Complete Graph.AlgorithmBegin    Take the input of the number of vertices ‘n’.    Construct a complete graph using e=n*(n-1)/2 edges, in ed[][].    Function EdgeColor() is used to Color the graph edges.    A) Assign color to current edge as c i.e. 1 initially.    B) If the same color is occupied by any of the adjacent edges, then       discard this color and go to flag again and try next color. ... Read More

C++ Program to Perform Edge Coloring of a Graph

Paul Richard
Updated on 30-Jul-2019 22:30:25

696 Views

In this program, we will perform Edge Coloring of a Graph in which we have to color the edges of the graph that no two adjacent edges have the same color. Steps in Example.AlgorithmBegin    Take the input of the number of vertices, n, and then number of edges, e, in the graph.    The graph is stored as adjacency list.    BFS is implemented using queue and colors are assigned to each edge. EndExample#include using namespace std; int n, e, i, j; vector g; vector color; bool v[111001]; void col(int n) {    queue q;    int c = ... Read More

C++ Program to Implement a Heuristic to Find the Vertex Cover of a Graph

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

879 Views

Vertex Cover of a Graph is to find a set of vertices V, such that for every edge connecting M to N in graph, either M or N (or both) are present in V. In this program, we Implement a Heuristic to Find the Vertex Cover of a Graph.AlgorithmBegin    1) Initialize a set S as empty.    2) Take an edge E of the connecting graph Say M and N.    3) Add both vertex to the set S.    4) Discard all edges in the graph with endpoints at M or N.    5) If some edge is ... Read More

C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order

Paul Richard
Updated on 30-Jul-2019 22:30:25

484 Views

This is C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order. This algorithm prints all the possible combination of each length from the given set of array in increasing order. The time complexity of this algorithm is O(n*(2^n)).AlgorithmBegin    For each length ‘i’ GenAllSubset() function is called:    1) In GenAllSubset(), if currLen is more than the reqLen then return.    2) Otherwise, if currLen is equal to reqLen then there will be a new sequence generated, print it.    3) If proceed with a start as ‘true’ and recursively call GenAllSubset() with incremented ... Read More

C++ Program to Find the Edge Connectivity of a Graph

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

571 Views

In this program we need to find the Edge Connectivity of a Graph. An Edge Connectivity of a Graph of a graph means it is a bridge, removing it graph will be disconnected. Number of connected components increases with the removing of bridge in a disconnected undirected graph.Functions and pseudocode:Begin    Function connections() is a recursive function to find out the connections:    A) Mark the current node un visited.    B) Initialize time and low value    C) Go through all vertices adjacent to this    D) Check if the subtree rooted with x has a connection to one ... Read More

Advertisements