Found 7347 Articles for C++

C++ Program to Find All Forward Edges in a Graph

Smita Kapse
Updated on 30-Jul-2019 22:30:26

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

C++ Program to Check Whether Topological Sorting can be Performed in a Graph

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

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

C++ Program to Check Cycle in a Graph using Topological Sort

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

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

C++ Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence

Smita Kapse
Updated on 30-Jul-2019 22:30:26

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

C++ Program to print the diamond shape

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

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

C++ program to print Happy Birthday

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

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

C++ program to convert time from 12 hour to 24 hour format

Smita Kapse
Updated on 30-Jul-2019 22:30:26

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

C++ Program to Implement Treap

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

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

C++ Program to Implement the Vizing’s Theorem

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

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

C++ Program to Demonstrate the Implementation of 4-Color Problem

Smita Kapse
Updated on 30-Jul-2019 22:30:26

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

Advertisements