Convert Binary Tree to Sum of Right Subtree in C++

Ayush Gupta
Updated on 02-Jan-2020 05:47:41

164 Views

In this tutorial, we will be discussing a program to convert a binary tree such that every node stores the sum of all nodes in its right subtree.For this, we will be provided with a binary tree. Our task is to return another tree where every node must be equal to the sum of the node and its right subtree.Example Live Demo#include using namespace std; //node structure of tree struct Node {    int data;    Node *left, *right; }; //creation of a new node struct Node* createNode(int item){    Node* temp = new Node;    temp->data = item;   ... Read More

Display Highest Amount from Corresponding Duplicate IDs in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:46:16

884 Views

To display highest amount from corresponding duplicate ids, use MAX() along with GROUP BY clause −mysql> create table DemoTable2003 (    CustomerId int,    Amount int ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2003 values(101, 560); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2003 values(102, 1080); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2003 values(101, 570); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable2003 values(102, 870); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable2003 values(101, 460); ... Read More

Convert a Binary Tree into its Mirror Tree in C++

Ayush Gupta
Updated on 02-Jan-2020 05:44:58

190 Views

In this tutorial, we will be discussing a program to convert a binary tree into its mirror tree.For this, we will be provided with a binary tree. Our task will be to swap the values on the left and the right end creating a mirror tree from the given binary tree.Example Live Demo#include using namespace std; //binary tree node structure struct Node{    int data;    struct Node* left;    struct Node* right; }; //creation of a new node with no child nodes struct Node* newNode(int data){    struct Node* node = (struct Node*)malloc(sizeof(struct Node));    node->data = data;    node->left ... Read More

Display Records by Grouping Dates in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:43:27

156 Views

To group dates in MySQL, use the GROUP BY clause −mysql> create table DemoTable2002 (    CustomerName varchar(20),    CustomerShippingDate datetime ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2002 values('Chris', '2019-01-10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2002 values('David', '2018-12-31'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2002 values('David', '2019-12-16'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2002 values('Chris', '2018-12-01'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * ... Read More

Print Last N Lines in C++

Ayush Gupta
Updated on 02-Jan-2020 05:42:18

420 Views

In this tutorial, we will be discussing a program to print the last N lines.For this, we will be provided with a string that consists of the new line character to denote the start of the next line and the number of lines to be printed from the last. Our task is to start from the last and print all the N lines counting from the last.Example#include using namespace std; #define DELIM '' //printing the last N lines void print_last_lines(char *str, int n){    if (n

Get Maximum Exam Date Using a User-Defined Variable in SQL

AmitDiwan
Updated on 02-Jan-2020 05:41:22

111 Views

To get the maximum exam date with a user-defined variable, the code is as follows −select date(max(yourColumnName )) into @yourVariableName  from yourTableName;To understand the above syntax, let us first create a table −mysql> create table DemoTable2001 (    ExamDate date ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2001 values('2019-01-10'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2001 values('2018-12-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2001 values('2018-11-18'); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable2001 values('2019-07-25'); Query OK, 1 ... Read More

Print Last 10 Lines in C++

Ayush Gupta
Updated on 02-Jan-2020 05:40:26

226 Views

In this tutorial, we will be discussing a program to print the last 10 lines.For this, we will be provided with a string that consists of the new line character to denote the start of the next line. Our task is to start from the last and print all the 10 lines counting from the last.Example#include using namespace std; #define DELIM '' //printing the last 10 lines void print_last_lines(char *str, int n){    if (n

MySQL Not Displaying Right Single Quotation Mark After Insertion

AmitDiwan
Updated on 02-Jan-2020 05:37:56

382 Views

To display right single quotation marks, you need to alter the table with COLLATE='utf8_unicode_ci'.Let us first create a table −mysql> create table DemoTable2000 (    Name varchar(20) ); Query OK, 0 rows affected (0.81 sec)Here is the query to use collate −mysql> ALTER TABLE DemoTable2000 COLLATE='utf8_unicode_ci'; Query OK, 0 rows affected (0.90 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert command −mysql> insert into DemoTable2000 values('Chris’s Brown'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable2000 values('David’s Miller'); Query OK, 1 row affected (0.67 sec) mysql> insert into DemoTable2000 values('Robert’s Downey'); Query ... Read More

Print Kite Pattern in C++

Ayush Gupta
Updated on 02-Jan-2020 05:37:01

976 Views

In this tutorial, we will be discussing a program to print the given Kite pattern.For this, we will be taking the input as N=5. Our task is to print the given Kite structure with the overall height of 2N+1 = 5. This includes 9 lines for the upper diamond structure and 2 for the lower incomplete diamond structure.Example Live Demo#include #include using namespace std; int main(){    int i, j, k, sp, space = 4;    char prt = '$';    //printing the upper half of the first diamond    for (i = 1; i = 1; sp--){          cout

Convert Date Timestamp to Return Only the Month Name in MySQL

AmitDiwan
Updated on 02-Jan-2020 05:35:56

223 Views

To return only the month name, you can use DATE_FORMAT() −mysql> create table DemoTable1999 (    ArrivalDate timestamp ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1999 values('2019-01-01 12:34:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1999 values('2019-12-31 10:04:00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1999 values('2018-10-11 04:04:30'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select * from DemoTable1999;This will produce the following output −+---------------------+ | ArrivalDate         | +---------------------+ ... Read More

Advertisements