Count Pairs of Adjacent Nodes Whose XOR is Odd in C++

Ayush Gupta
Updated on 10-Feb-2020 10:50:15

141 Views

In this tutorial, we will be discussing a program to find the number of pairs of adjacent nodes whose XOR is an odd number.For this we will be provided with a binary tree. Our task is to count the number of pairs of adjacent elements whose XOR is an odd number.Example Live Demo#include using namespace std; //node structure of tree struct Node {    int data;    struct Node *left, *right; }; //finding the pairs whose XOR //is odd int count_pair(Node* root, Node *parent=NULL){    if (root == NULL)       return 0;    //checking pair of XOR is ... Read More

Use Python Object in C++

Rajendra Dharmkar
Updated on 10-Feb-2020 10:49:28

874 Views

Here is an example in which a simple Python object is wrapped and embedded. We are using  .c for this, c++ has similar steps −class PyClass(object):     def __init__(self):         self.data = []     def add(self, val):         self.data.append(val)     def __str__(self):         return "Data: " + str(self.data) cdef public object createPyClass():     return PyClass() cdef public void addData(object p, int val):     p.add(val) cdef public char* printCls(object p):     return bytes(str(p), encoding = 'utf-8')We compile with cython pycls.pyx (use --cplus for c++) to generate ... Read More

Change JSlider Position to Horizontal or Vertical in Java

raja
Updated on 10-Feb-2020 10:48:18

412 Views

A JSlider is a subclass of JComponent class and it is similar to scroll bar which allows the user to select a numeric value from a specified range of integer values. It has a knob which can slide on a range of values and can be used to select a particular value. A JSlider can generate a ChangeListener interface and the important methods of JSlider are getMaximum(), getMinimum(), getOrientation(), getValue() and setValue(). The default position of a JSlider is horizontal and we can also set the position to vertical programmatically by selecting a menu item from a menu bar. It can generate an ActionListener interface ... Read More

C++ 'a.out' Not Recognised as a Command

Pythonista
Updated on 10-Feb-2020 10:47:17

5K+ Views

Having entered following command from linux terminal −$ g++ helloworld.cppThe a.out file should be created in the current working directory if the compilation is successful. Check if a.out is created.To execute enter following from command line −$ ./a.outIn most cases, output of your source program is displayed. However, as in your case, error message indicating a.out is not executable is appearing. See the properties of a.out and make it executable (if not already) by following command −$ chmod +x a.outYou may require sudo privilege for this. In all probability this should work. all the bestRead More

Set Tooltip for Each Column of JTableHeader in Java

raja
Updated on 10-Feb-2020 10:46:28

1K+ Views

A JTableHeader is a subclass of JComponent class, When we create a JTable object, the constructor creates a new JTableHeader object to manage the table component's header. A JTable supplies a setTableHeader() method that establishes the table header component's JTableHeader object and a getTableHeader() method that returns a reference to the table header component's JTableHeader object. We can set a tooltip text to each column of a JTableHeader by overriding the getToolTipText() method of JTableHeader class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class JTableHeaderToolTipTest extends JPanel {    private DefaultTableModel dmodel;    private JTable table;    private JScrollPane jsp;    public JTableHeaderToolTipTest() ... Read More

Set Orientation of JTextArea from Right to Left in Java

raja
Updated on 10-Feb-2020 10:43:39

1K+ Views

A JTextArea is a subclass of JTextComponent class and it is a multi-line text component to display the text or allow a user to enter the text. A JTextArea can generate a CaretListener interface when we are trying to implement the functionality of the JTextArea. By default, a JTextarea allows the orientation from left to right, if the user wants to enter a text from right to left by using the setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT) method of JTextArea class.Exampleimport java.awt.*; import javax.swing.event.*; import javax.swing.*; public class JTextAreaOrientationTest extends JFrame {    private JTextArea textArea;    public JTextAreaOrientationTest() {       setTitle("JTextAreaOrientation Test");       textArea = new ... Read More

Combine Functions in MySQL

Chandu yadav
Updated on 10-Feb-2020 10:43:23

593 Views

Combining of functions in MySQL is quite possible by providing a function as the argument of other function. It is also called nesting of functions. To understand it, consider some examples belowmysql> Select UPPER(CONCAT('www.', 'tutorialspoint', '.com'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | WWW.TUTORIALSPOINT.COM | +------------------------+ 1 row in set (0.00 sec) mysql> Select LOWER(CONCAT('WWW.', 'TUTORIALSPOINT', '.COM'))As Tutorials; +------------------------+ | Tutorials              | +------------------------+ | www.tutorialspoint.com | +------------------------+ 1 row in set (0.00 sec)The above queries combine UPPER() and LOWER() function with CONCAT() function.Similarly, we can combine more ... Read More

Change JButton Text Dynamically in Java

raja
Updated on 10-Feb-2020 10:41:10

9K+ Views

A JButton is a subclass of AbstractButton and it can be used for adding platform-independent buttons in a Java Swing application. A JButon can generate an ActionListener interface when the user clicking on a button, it can also generate the MouseListener and KeyListener interfaces. By default, we can create a JButton with a text and also can change the text of a JButton by input some text in the text field and click on the button, it will call the actionPerformed() method of ActionListener interface and set an updated text in a button by calling setText(textField.getText()) method of a JButton class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public ... Read More

Use MySQL IF Function Within SELECT Statement

Monica Mona
Updated on 10-Feb-2020 10:40:37

3K+ Views

It is quite possible to use MySQL IF() function within SELECT statement by providing the name of the column along with a condition as the first argument of IF() function. To understand it, consider the following data from table ‘Students’.mysql> Select * from Students; +----+-----------+-----------+----------+----------------+ | id | Name      | Country   | Language | Course         | +----+-----------+-----------+----------+----------------+ | 1  | Francis   | UK        | English  | Literature     | | 2  | Rick      | USA       | English  | History        | ... Read More

Effect of Negative Value in MySQL TRUNCATE Function

Sravani S
Updated on 10-Feb-2020 10:39:10

408 Views

If we specify the negative value of the second argument then the digits before the decimal point would be deleted without rounded off. The number of digits to be deleted depends upon the value of the negative second argument. Following examples will demonstrate the change, depending upon the negative value of the second argument, in the output of TRUNCATE() function.  mysql> Select TRUNCATE(1789.456, -1); +-----------------------+ | TRUNCATE(1789.456, -1) | +-----------------------+ |                  1780 | +-----------------------+ 1 row in set (0.00 sec)  The query above returns 1780 because the first digit before the decimal point ... Read More

Advertisements