- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
205 Views
In this section, we shall consider a C++ program to find all forward edges in a graph.AlgorithmsFor topo functionBegin Declare function topo() Declare pointer v, m[][5] and i of the integer datatype. x = new Node_Inf. x->n = i. x->S_Time = c. Call function Push_Node(x). v[i] = 1. for (int j = 0; j < 5; j++) if (m[i][j] == 0) then continue; else ... Read More
480 Views
In a Directed Acyclic Graph, we can sort vertices in linear order using topological sort.Topological sort is only work on Directed Acyclic Graph. In a Directed Acyclic Graph (DAG), there can be more than one topological sort.In the following C++ program, we shall perform topological sort to check existence of a cycle in a graph.AlgorithmsFor function Topo_SortBegin Define function Topo_Sort() Declare x to the integer datatype, vstd[] of the Boolean array and Stack as a stack. Pass them as parameter. Initialize vstd[x] = true to mark the current node ... Read More
300 Views
In a Directed Acyclic Graph, we can sort vertices in linear order using topological sort.Topological sort is only work on Directed Acyclic Graph. In a Directed Acyclic Graph (DAG), there can be more than one topological sort.We shall consider a C++ program, which will perform topological sort to check cycle in a graph.For exampleAlgorithmsTopological Sort: Begin Declare topo_sort(int *v, int T_S[][5], int i) function a = new NodeInfo. a->n = i a->S_Time = cn. Call push_node(a) function to insert data. v[i] = 1. ... Read More
86 Views
It is a program to check possibility of construction of a graph in a given degree sequence.InputIt takes the no of edges and vertexes.OutputIt shows the random values of a created graph.AlgorithmsBegin Declare a function RandomGraphs(). Declare NoEdge and NoVertex of the integer datatype and pass them as parameter. Declare i, j, e[NoEdge][2], c of the integer datatype. Initialize i = 0. while (i < NoEdge) do e[i][0] = rand()%NoVertex+1. e[i][1] = rand()%NoVertex+1. if(e[i][0] == ... Read More
379 Views
This is a C++ Program to print the diamond shape.AlgorithmBegin Take the no of rows n means the dimension of the diamond shape as input. Declare the variables i, j and initialize space=1. Initialize space = n-1. Run for loop till n. Run for loop to print space. Decrease space. Run for loop to print stars. Now do the same thing in reverse order. Initialize space = 1. Run for loop till n. Run for loop to print space. ... Read More
5K+ Views
This is a C++ program to print Happy Birthday.AlgorithmBegin Take a str1 which takes the next character of our desired ouput like for H it will be G. Assign the string to a pointer p. Make a while loop till *p != NULL. Go next character of the string print it and after that go the nextposition of string. Print the result. EndExample#include using namespace std; main(){ char str[]="G`ooxAhqsgc`x",*p; p=str; while(*p!='\0') ++*p++; cout
914 Views
This is a C++ program to convert time from 12 hour to 24 hour format.AlgorithmBegin In main(), If median = pm Check if entered hours is less than 12 Then add 12 to hours and print the time in 24 hours format. Check if entered hours is equal to 12 Then print “00” as hours and print the time in 24 hours format. Else If median=am Check if entered hours is less than 12 Then print ... Read More
1K+ Views
This is a C++ program to implement Treap. Treap data structure is basically a randomized binary search tree. Here, we shall consider insert, delete and search operations on this.Functions and descriptionsfunction rotLeft() for left rotationFirst rotate the tree then set new root.function rotRight() for right rotationFirst rotate the tree then set new root.function insetNod() to insert a given key into treap with priority recursively −If root = nullptr return data as root. If given data is less then root node, Insert data in left subtree. Rotate left if heap property violated. else Insert data in right ... Read More
147 Views
Vizing’s theorem state that the chromatic index of simple graph can be either maxdegree or maxdegree+1. Here, chromatic index means maximum color needed for the edge coloring of the graph.This is a C++ program to implement the Vizing’s Theorem.AlgorithmBegin Take the number of vertices and edges as input. Take the vertex pair for the edges. function EdgeColor() : Color the graph edges. 1) Assign color to current edge as c i.e. 1 initially. 2) If the same color is occupied by any of the adjacent edges, then discard ... Read More
495 Views
This is a C++ Program to Demonstrate the Implementation of 4-Color Problem.AlgorithmBegin Develop function issafe() to check if the current color assignment is safe for vertex v i.e. checks whether the edge exists or not. If it exists, then next check whether the color to be filled in the new vertex is already used by its adjacent vertices. End Begin Function graphColoringtil(bool graph[V][V], int m, int col[], int v) solve 4 coloring problem: Here, g[V][V] = It is a 2D array where V is the number of vertices in graph ... Read More