Found 26504 Articles for Server Side Programming

Convert BST to Max Heap in C++

Ayush Gupta
Updated on 16-Jan-2020 07:08:43

556 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
Updated on 16-Jan-2020 07:05:46

356 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
Updated on 16-Jan-2020 07:02:06

188 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
Updated on 16-Jan-2020 06:59:07

134 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

Convert an Array to a Circular Doubly Linked List in C++

Ayush Gupta
Updated on 16-Jan-2020 06:55:53

361 Views

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

Convert an arbitrary Binary Tree to a tree that holds Children Sum Property in C++

Ayush Gupta
Updated on 16-Jan-2020 06:50:38

354 Views

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 Live Demo#include #include using namespace std; //node structure for binary tree class node{    public:    int data;    node* left;    node* right; ... Read More

Convert all substrings of length ‘k’ from base ‘b’ to decimal in C++

Ayush Gupta
Updated on 16-Jan-2020 06:45:26

99 Views

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

Difference between the and$ operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:43:02

498 Views

$ operatorOperator is used to define variables in php. For example, message. Such variables can contain any type of value like int, string, etc.$$ operator$$ is a special operator that contains the name of another variable and can be used to access the value of that variable.ExampleFollowing the example, shows the usage of '′vs′$' operators. Live Demo    PHP Example     Outputmessage Welcome to Tutorialspoint

Difference between the AND and && operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:39:02

430 Views

'AND' Logical operator'AND' operator is a logical AND operator but has low precedence to = operator.'&&' Logical operator'&&' is also a logical AND operator but has high precedence to = operator.ExampleFollowing the example, shows the difference of 'AND' vs '&&' operators. Live Demo    PHP Example     Output$result = $x AND $y bool(true) $result = $x && $y bool(false)

Difference between the | and || or operator in php

Mahesh Parahar
Updated on 13-Jan-2020 06:35:31

370 Views

'|' Bitwise OR operator'|' operator is a bitwise OR operator and is used to set the bit to 1 if any of the corresponding bit is 1.'||' Logical Or operator'||' is a logical Or operator and works on complete operands as whole.ExampleFollowing example, shows usage of '|' vs '||' operators. Live Demo    PHP Example     Output$x | $y = 3 $x || $y = 1

Advertisements