Programming Articles - Page 2138 of 3363

Convert String into Binary Sequence in C++

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

1K+ Views

In this tutorial, we will be discussing a program to convert string into Binary sequence.For this we will be provided with a string of characters. Our task is to convert each of the character into its binary equivalent and print it out spaced between for different characters.Example Live Demo#include using namespace std; //converting into binary equivalent void convert_binary(string s){    int n = s.length();    for (int i = 0; i 0){          (val % 2)? bin.push_back('1') :          bin.push_back('0');          val /= 2;       }       reverse(bin.begin(), bin.end());       cout

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

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

329 Views

In this tutorial, we will be discussing a program to convert a singly linked list into XOR 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 XOR linked list.Example Live Demo#include using namespace std; //node structure of linked list struct Node {    int data;    struct Node* next; }; //creation of new node Node* newNode(int data){    Node* temp = new Node;    temp->data = data;    temp->next = NULL;    return temp; } //printing singly linked list void print(Node* ... Read More

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

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

602 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

778 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

344 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

How to implement LongPredicate using lambda and method reference in Java?

raja
Updated on 14-Jul-2020 12:06:47

304 Views

LongPredicate is a functional interface defined in java.util.function package. This interface can be used mainly for evaluating an input of type long and returns an output of type boolean. LongPredicate can be used as an assignment target for a lambda expression or method reference. It contains one abstract method: test() and three default methods: and(), negate() and or().Syntax@FunctionalInterface interface LongPredicate {  boolean test(long value); }Example of Lambda Expressionimport java.util.function.LongPredicate; public class LongPredicateLambdaTest {    public static void main(String args[]) {       LongPredicate longPredicate = (long input) -> {    // lambda expression          if(input == 50) {       ... Read More

Maximum spiral sum in Binary Tree in C++

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

205 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

802 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

293 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

Advertisements