Found 7347 Articles for C++

Convert singly linked list into circular linked list in C++

Ayush Gupta
Updated on 22-Jan-2020 07:07:07

367 Views

In this tutorial, we will be discussing a program to convert a singly linked list into circular linked list.For this we will be provided with a singly linked list. Our task is to take the elements of that list and get it converted into a circular linked list.Example Live Demo#include //node structure of linked list struct Node {    int data;    struct Node* next; }; //converting singly linked list //to circular linked list struct Node* circular(struct Node* head){    struct Node* start = head;    while (head->next != NULL)       head = head->next;    //assigning start to ... Read More

Convert min Heap to max Heap in C++

Ayush Gupta
Updated on 22-Jan-2020 07:04:04

498 Views

In this tutorial, we will be discussing a program to convert min heap to max heap.For this we will be provided with the array representation of the min heap. Our task is to convert that given min heap to max heap in O(n) time complexity.Example Live Demo#include using namespace std; //converting a given subtree into a heap void convert_arrayheap(int arr[], int i, int n){    int l = 2*i + 1;    int r = 2*i + 2;    int largest = i;    if (l < n && arr[l] > arr[i])       largest = l;    if (r ... Read More

Convert Hexadecimal value String to ASCII value String in C++

Ayush Gupta
Updated on 22-Jan-2020 07:00:38

2K+ Views

In this tutorial, we will be discussing a program to convert hexadecimal value string to ASCII value string.For this we will be provided with a string with some hexadecimal values. Our task is to get that hexadecimal value and convert it into equivalent ASCII values.Example Live Demo#include using namespace std; string convert_ASCII(string hex){    string ascii = "";    for (size_t i = 0; i < hex.length(); i += 2){       //taking two characters from hex string       string part = hex.substr(i, 2);       //changing it into base 16       char ch ... Read More

Convert given time into words in C++

Ayush Gupta
Updated on 22-Jan-2020 06:56:25

224 Views

In this tutorial, we will be discussing a program to convert given time into words. For this we will be provided with a specific time in the digital format.Our task is to convert that particular time into wordsExample#include using namespace std; //printing time in words void convert_time(int h, int m){    char nums[][64] = {       "zero", "one", "two", "three", "four",       "five", "six", "seven", "eight",       "nine", "ten", "eleven", "twelve",       "thirteen", "fourteen", "fifteen",       "sixteen", "seventeen", "eighteen",       "nineteen", "twenty", "twenty       one", ... Read More

Maximum spiral sum in Binary Tree in C++

Narendra Kumar
Updated on 03-Jun-2020 08:17:12

86 Views

In this problem, we are given a binary tree. Our task is to create a program that will find the maximum spiral sum in a binary tree in C++.Spiral sum of a binary tree is the sum of nodes that are encountered in the spiral traversal of the binary tree.In the spiral traversal of a tree, the nodes are traversed from the root to the leaf node. The traversal takes place from left to right then for the next level from right to left and so on for the further levels.Example −Output −5Explanation −We will consider the spiral traversal until the ... Read More

Maximum size subset with given sum in C++

Narendra Kumar
Updated on 21-Jan-2020 11:30:13

625 Views

Problem statementGiven an array of N elements and sum. We need to find size of maximum size subset whose sum is equal to given sumExampleIf input array is arr = { 2, 3, 5, 10 } and sum = 20 then output will be 4 as −2 + 3 + 5 + 10 = 20 which is equal to given sumAlgorithmWe can use dynamic programming to solve this problem.To count the maximal subset, we use another DP array (called as ‘count array’) where count[i][j] is maximal of.count[i][j-1]. Here current element is not considered.scount[i- X][j-1] + 1. Here X is value ... Read More

Maximum segment value after putting k breakpoints in a number in C++

Narendra Kumar
Updated on 03-Jun-2020 08:19:11

179 Views

In this problem, we are given a string that denotes a large number and an integer k roar denotes the number of breakpoints. Our task is to create a program that will find the maximum segment value after putting L breakpoints in a number.Here, we have to find the maximum number that can be generated after putting k breakpoint in the number given by the string.Let's take an example to understand the problemInput − string = “45972”, k = 3Output − 97Explanation −All possible number is: 45    9    7    2 4    59    7    2 ... Read More

Maximum removal from array when removal time >= waiting time in C++

Narendra Kumar
Updated on 03-Jun-2020 08:20:38

52 Views

In this problem, we are given an array of N elements. Our task is to find the maximum removal from the array when removal time >= waiting time.So, here we will be removing the elements of the array. The value of the element of the array denotes the removal time(time taken to remove the element from the array).The element has a waiting time which is the time it will have to wait till it will get removed.The element can be removed from the only if the removal time is greater than the time it has to wait.We have to find ... Read More

Maximum profit from sale of wines in C++

Narendra Kumar
Updated on 21-Jan-2020 11:17:53

127 Views

Problem statementGiven n wines in a row, with integers denoting the cost of each wine respectively. Each year you can sale the first or the last wine in the row. The price of wines increases over time. Let the initial profits from the wines be P1, P2, P3…Pn. On the Yth year, the profit from the ith wine will be Y*Pi. For each year, your task is to print start or end denoting whether first or last wine should be sold. Also, calculate the maximum profit from all the wines.ExampleIf wine prices are {2, 4, 6, 2, 5} then output ... Read More

Maximum Primes whose sum is equal to given N in C++

Narendra Kumar
Updated on 03-Jun-2020 08:21:44

106 Views

In this problem, we are given a number n. Our task is to find the maximum count of primes whose sum is equal to given N.Here, we will find the maximum number of prime numbers that when added will be equal to the number.The prime number are those number which can be divide by either themselves or one.let's take an example to understand the problem −Input − N = 9Output − 4Explanation −9 can be repressed as the sum of prime numbers in the following ways: 2, 2, 2, 3 3, 3, 3 2, 2, 5 2, 7 Out of ... Read More

Advertisements