Found 7346 Articles for C++

How to convert std::string to LPCWSTR in C++?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see how to convert C++ wide string (std::wstring) to LPCWSTR. The LPCWSTR is the (Long Pointer to Constant Wide STRing). It is basically the string with wide characters. So by converting wide string to wide character array we can get LPCWSTR. This LPCWSTR is Microsoft defined. So to use them we have to include Windows.h header file into our program.To convert std::wstring to wide character array type string, we can use the function called c_str() to make it C like string and point to wide character string.Example Code#include #include using namespace std; main(){    wstring ... Read More

How to convert std::string to LPCSTR in C++?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see how to convert C++ string (std::string) to LPCSTR. The LPCSTR is the (Long Pointer to Constant STRing). It is basically the string like C. So by converting string to character array we can get LPCSTR. This LPCSTR is Microsoft defined. So to use them we have to include Windows.h header file into our program.To convert std::string to C like string we can use the function called c_str().Example Code#include #include using namespace std; main() {    string my_str = "Hello World";    LPTSTR long_string = new TCHAR[my_str.size() + 1]; //define    an array with size ... Read More

C++ Program to Find Largest Rectangular Area in a Histogram

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

268 Views

This is a C++ Program to find largest Rectangular Area in a HistogramAlgorithmof function getArea():Begin    Create an empty stack.    Initialize the largest_area.    Do a while loop start from first bar for every bar hist[i], where i = 0 to       less than n:    If stack is empty or hist[i] is higher than the bar at top of stack, then       push ‘i’ to stack.    Else       this bar is smaller than the top of stack, then keep removing the       top of stack while top of the ... Read More

C++ Program to Implement First Fit Decreasing for 1-D Objects and M Bins

Nancy Den
Updated on 30-Jul-2019 22:30:25

112 Views

Here is a C++ Program to implement First Fit Decreasing for 1-D objects and M binsRequired functions and pseudocode:Begin    function binPack() returns number of bins required.    Initialize binC = 0    Initialize an array to store binVal.    Place items one by one.    function sort() to perform bubble sort in the descending order. EndExample Code#include using namespace std; void binPack(int *a, int s, int n) {    int binC = 0;    int binVal[n];    for (int i = 0; i < n; i++)    binVal[i] = s;    for (int i = 0; i < ... Read More

C++ Program to Implement The Edmonds-Karp Algorithm

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

3K+ Views

This is a C++ Program to Implement the Edmonds-Karp algorithm to calculate maximum flow between source and sink vertex.Algorithm:Begin    function edmondsKarp() :       initiate flow as 0.       If there is an augmenting path from source to sink, add the path to flow.       Return flow. EndExample Code#include #include #include #include #include using namespace std; int c[10][10]; int flowPassed[10][10]; vector g[10]; int parList[10]; int currentPathC[10]; int bfs(int sNode, int eNode)//breadth first search {    memset(parList, -1, sizeof(parList));    memset(currentPathC, 0, sizeof(currentPathC));    queue q;//declare queue vector    q.push(sNode);    parList[sNode] = -1;//initialize parlist’s ... Read More

C++ Program to Implement Network_Flow Problem

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

450 Views

This is a C++ Program to implement Network_Flow problem using Ford Fulkerson algorithm.Algorithms:Begin    function bfs() returns true if there is path from source s to sink t in    the residual graph which indicates additional possible flow in the graph. End Begin    function fordfulkarson() return maximum flow in given graph:    A) initiate flow as 0.    B) If there is an augmenting path from source to sink, add the path to flow.    C) Return flow. EndExample Code#include #include #include #include #define n 7 using namespace std; bool bfs(int g[n][n], int s, int ... Read More

C++ Program to Perform Operations in a BST

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

2K+ Views

         A Binary Search Tree is a sorted binary tree in which all the nodes will have following properties−The right sub-tree of a node has a key greater than to its parent node's key.The left sub-tree of a node has a key lesser than to its parent node's key.All key values are distinct.Each node cannot have more than two children.Class Descriptions:Begin    class BST to declare following functions:       search() = To search an item in BST.       initialize temp = root;       while(temp != NULL)          Increase ... Read More

C++ Program to Find Maximum Number of Edge Disjoint Paths

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

103 Views

This is a C++ program to find Maximum Number of Edge Disjoint Paths which means shortest subset path or maximum flow between two vertices.Algorithms:Begin    function bfs() returns true if there is path from source s to sink t in    the residual graph which indicates additional possible flow in the    graph. End Begin    function findDisPath() is used to return maximum flow in given    graph:    A) Initiate flow as 0.    B) If there is an augmenting path from source to sink, add the path to flow.    C) Return flow. EndExample Code#include #include ... Read More

C++ Program to Perform Greedy Coloring

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

674 Views

Here is a C++ Program to Perform Greedy ColoringAlgorithm:Begin    Take the number of vertices and edges as input.    Create function greedyColoring() to assign color to vertices:    A) Assign the first color to first vertex.    B) Initialize the remaining vertices.    C) Declare a temporary array to store the available colors.    D) Assign color to the remaining vertices.    Print the solution. EndExample Code#include #include using namespace std; int n,e,i,j; vector g; vector col; bool visit[1001]; void greedyColoring() {    col[0] = 0;    for (i=1;i

C++ Program to Implement Dijkstra’s Algorithm Using Set

Nancy Den
Updated on 30-Jul-2019 22:30:25

467 Views

This is a C++ Program to Implement Dijkstra’s Algorithm using Set. Here we need to have two sets. We generate a shortest path tree with given source node as root. One set contains vertices included in shortest path tree and other set includes vertices not yet included in shortest path tree. At every step, we find a vertex which is in the other set (set of not yet included) and has minimum distance from source.Algorithm:Begin    function dijkstra() to find minimum distance:    1) Create a set Set that keeps track of vertices included in shortest    path tree, Initially, ... Read More

Advertisements