Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Ayush Gupta
Page 31 of 44
Convert Ternary Expression to a Binary Tree in C++
In this tutorial, we will be discussing a program to convert ternary expression to a binary tree.For this we will be provided with a ternary expression. Our task is to convert the given expression in the form of a binary tree depending upon the various paths(choices) possible.Example#include using namespace std; //node structure of tree struct Node { char data; Node *left, *right; }; //creation of new node Node *newNode(char Data){ Node *new_node = new Node; new_node->data = Data; new_node->left = new_node->right = NULL; return new_node; } //converting ternary expression into binary tree Node *convertExpression(string ...
Read MoreConvert the array such that the GCD of the array becomes 1 in C++
In this tutorial, we will be discussing a program to convert the array such that the GCD of the array becomes one.For this we will be provided with an array and a positive integer k. Our task is to convert the array elements such that the GCD of elements is 1 while only dividing the array elements by k any number of times until the element is less than k.Example#include using namespace std; //calculating the GCD of array int calculate_gcd(int* arr, int n){ int gcd = arr[0]; for (int i = 1; i < n; i++) ...
Read MoreConvert the ASCII value sentence to its equivalent string in C++
In this tutorial, we will be discussing a program to convert the ASCII value sentence to its equivalent string.For this we will be provided with a string containing the ASCII codes. Our task is to convert the given string into the equivalent characters and print it back.Example#include using namespace std; //converting the ASCII sequence into //character string void convert_ASCII(string str, int len){ int num = 0; for (int i = 0; i < len; i++) { //appending the current digit num = num * 10 + (str[i] - '0'); //checking if number is within range if (num >= 32 && num
Read MoreConvert the string into palindrome string by changing only one character in C++
In this tutorial, we will be discussing a program to convert the string into palindrome string by changing only one character.For this we will be provided with a string. Our task is to convert the given string into a palindrome by changing only one character.Example#include using namespace std; //checking if conversion to palindrome //is possible bool if_palindrome(string str){ int n = str.length(); //counting number of characters //to be changed int count = 0; for (int i = 0; i < n/2; ++i) if (str[i] != str[n - i - 1]) ++count; return (count
Read MoreConvert the undirected graph into directed graph such that there is no path of length greater than 1 in C++
In this tutorial, we will be discussing a program to convert the undirected graph into a directed graph such that there is no path of length greater than 1.For this we will be provided with an undirected graph. Our task is to convert that graph into a direct one given no path has a length greater than 1.Example#include using namespace std; #define N 100005 //storing the graph vector gr[N]; //storing colour of each vertex int colour[N]; vector edges; bool bip; //adding edges to the graph void add_edge(int x, int y){ gr[x].push_back(y); gr[y].push_back(x); edges.push_back(make_pair(x, y)); } //checking ...
Read MoreConvert all substrings of length 'k' from base 'b' to decimal in C++
In this tutorial, we will be discussing a program to convert all substrings of length ‘k’ from base ‘b’ to decimal.For this we will be provided with a string of some certain length. Our task is to take the substrings from the given string of size ‘k’ and get it converted into the decimal numbers from being in base ‘b’.Example#include using namespace std; //converting the substrings to decimals int convert_substrings(string str, int k, int b){ for (int i=0; i + k = 0; i--){ sum = sum + ((sub.at(i) - '0') * pow(b, counter)); counter++; } cout
Read MoreConvert an arbitrary Binary Tree to a tree that holds Children Sum Property in C++
In this tutorial, we will be discussing a program to convert an arbitrary binary tree to a tree that holds children sum property.For this we will be provided with a binary tree. Our task is to convert it into the binary tree that follows the children sum property. But the restriction is that we can only increment the values present in the nodes, neither can change the structure of the tree or decrement values in the node.Example#include #include using namespace std; //node structure for binary tree class node{ public: int data; node* left; node* right; ...
Read MoreConvert an Array to a Circular Doubly Linked List in C++
In this tutorial, we will be discussing a program to convert an array to a circular doubly linked list.For this we will be provided with an array. Our task is to take the elements of the array and get it converted into a circular doubly linked list.Example#include using namespace std; //node structure for doubly linked list struct node{ int data; struct node *next; struct node *prev; }; //node creation struct node* getNode(){ return ((struct node *)malloc(sizeof(struct node))); } //printing the list int print_list(struct node *temp){ struct node *t = temp; if(temp == NULL) ...
Read MoreConvert an array to reduced form (Hashing) in C++
In this tutorial, we will be discussing a program to convert an array to its reduced form using hashing.For this we will be provided with an array. Our task is to convert the given array in its reduced form such that it only contains elements ranging from 0 to n-1.Example#include using namespace std; //converting array to its reduced form void convert(int arr[], int n){ // copying the elements of array int temp[n]; memcpy(temp, arr, n*sizeof(int)); sort(temp, temp + n); //creating a hash table unordered_map umap; int val = 0; for (int ...
Read MoreConvert an array to reduced form (Using vector of pairs) in C++
In this tutorial, we will be discussing a program to convert an array to its reduced form using vector of pairs.For this we will be provided with an array. Our task is to convert the given array in its reduced form such that it only contains elements ranging from 0 to n-1.Example#include using namespace std; //converting array to its reduced form void convert(int arr[], int n){ //creating a vector of pairs vector v; //putting elements in vector //with their indexes for (int i = 0; i < n; i++) v.push_back(make_pair(arr[i], ...
Read More