Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 31 of 44

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

Ayush Gupta
Ayush Gupta
Updated on 22-Jan-2020 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
Ayush Gupta
Updated on 22-Jan-2020 367 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

Convert given string so that it holds only distinct characters in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 285 Views

In this tutorial, we will be discussing a program to convert given string so that it holds only distinct characters.For this we will be provided with a string. Our task is to traverse through the string and replace all the recurring characters with any random characters that are not already present into the string.Example Live Demo#include using namespace std; //collecting the distinct characters //in the string int calculate_zero(int i, int occurrences[]){    while (i < 26) {       //if it is present only once       if (occurrences[i] == 0)          return i;     ...

Read More

Convert given array to Arithmetic Progression by adding an element in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 247 Views

In this tutorial, we will be discussing a program to convert given array to arithmetic progression by adding an element.For this we will be provided with an array. Our task is to convert the given array into an arithmetic progression by adding a single element to it and return the added element. If it is not possible, return -1.Example Live Demo#include using namespace std; //returning the number to be added int print_number(int arr[], int n){    sort(arr, arr+n);    int d = arr[1] - arr[0];    int numToAdd = -1;    bool numAdded = false;    for (int i = 2; ...

Read More

Convert from any base to decimal and vice versa in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 1K+ Views

In this tutorial, we will be discussing a program to convert from any base to a decimal and vice versa.For this we will be provided with an integer and its base. Our task is to convert the number to its decimal equivalent. Further we will also be performing the reverse of this procedure as well.Example Live Demo#include #include //returning values of a character int val(char c) {    if (c >= '0' && c = 0; i--) {       if (val(str[i]) >= base) {          printf("Invalid Number");          return -1;   ...

Read More

Convert BST to Min Heap in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 416 Views

In this tutorial, we will be discussing a program to convert a binary search tree to a min heap.For this we will be provided with a binary search tree. Our task is to convert the given binary search tree into a min heap such that following the condition of the binary search tree when elements are compared with themselves.Example Live Demo#include using namespace std; //node structure of BST struct Node {    int data;    Node *left, *right; }; //node creation struct Node* getNode(int data) {    struct Node *newNode = new Node;    newNode->data = data;    newNode->left = ...

Read More

Convert BST to Max Heap in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 623 Views

In this tutorial, we will be discussing a program to convert a binary search tree to a max heap.For this we will be provided with a binary search tree. Our task is to convert the given binary search tree into a max heap such that following the condition of the binary search tree when elements are compared with themselves.Example Live Demo#include using namespace std; //node structure of BST struct Node {    int data;    Node *left, *right; }; //node creation struct Node* getNode(int data) {    struct Node* newNode = new Node;    newNode->data = data;    newNode->left = ...

Read More

Convert array into Zig-Zag fashion in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 392 Views

In this tutorial, we will be discussing a program to convert an array into zig-zag fashion.For this we will be provided with an array containing distinct elements. Our task is to rearrange the elements of the given array in a zig zag fashion with greater and smaller elements alternatively as compared to the previous element.Example Live Demo#include using namespace std; //converting into zig-zag fashion void convert_zigzag(int arr[], int n) {    //flag denotes the greater or smaller relation    bool flag = true;    for (int i=0; i arr[i+1])          swap(arr[i], arr[i+1]);       } else ...

Read More

Convert an array to reduced form (Using vector of pairs) in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 233 Views

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 Live Demo#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++)       ...

Read More

Convert an array to reduced form (Hashing) in C++

Ayush Gupta
Ayush Gupta
Updated on 16-Jan-2020 165 Views

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 Live Demo#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 ...

Read More
Showing 301–310 of 433 articles
« Prev 1 29 30 31 32 33 44 Next »
Advertisements