Sorting in C++

George John
Updated on 30-Jul-2019 22:30:25
In this section we will see how to perform sorting algorithm in C++. A sorted array is an array in which each of the elements are sorted in some order such as numerical, alphabetical etc. There are many algorithms to sort a numerical array such as bubble sort, insertion sort, selection sort, merge sort, quick sort, heap sort etc. More details about sorting the array using selection sort are given below.The selection sort is a sorting method that yields a sorted array. It does so by repeatedly finding the smallest element in the array and interchanging it with the element ... Read More

C++ Program to Implement Sorted Singly Linked List

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
In data structure, Linked List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. Into a linked list the entry point is called the head of the list.Each node in the list stores the contents and a pointer or reference to the next node in the list, in a singly linked list. Singly linked list does not store any pointer or reference to the previous node.Developing a C++ program to implement sorted ... Read More

How to add check box list in alert dialog?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25
How to add checkbox list in alert dialog?This example demonstrates How to add checkbox list in the alert dialogStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     In the above code, we have taken text view.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.TargetApi; import android.content.DialogInterface; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { ... Read More

Java Program to create a Calculator

Samual Sam
Updated on 30-Jul-2019 22:30:25
To create a calculator with Java Swings, try the following code −Exampleimport java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JTextField; public class SwingDemo extends JFrame implements ActionListener {    JButton one, two, three, four, five, six, seven, eight, nine, num0, add, sub, div, mult, equalto, exit, point, reset;    JTextField textField;    String s = "", ope = "";    int flag = 0;    double total1;    double input1, input2;    void total(double input1, double inout2, String ope) {       String total;       if (ope.equalsIgnoreCase("+")) ... Read More

Add a temporary column in MySQL where the values depend on another column?

Samual Sam
Updated on 30-Jul-2019 22:30:25
You can use CASE statement for this and set conditions to get result in the temporary column.Let us first create a table −mysql> create table DemoTable    (    EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeName varchar(20),    EmployeeSalary int,    EmployeeExperience int    ); Query OK, 0 rows affected (0.64 sec)Following is the query to insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeName, EmployeeSalary, EmployeeExperience) values('Larry', 4500, 5); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(EmployeeName, EmployeeSalary, EmployeeExperience) values('Mike', 130000, 8); Query OK, 1 row affected (0.21 sec) mysql> ... Read More

How to update record in MongoDB without replacing the existing fields?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
You can use $set operator for this Let us first create a collection with documents −> db.updateRecordDemo.insertOne({"StudentName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6f95de8cc557214c0e0a") } > db.updateRecordDemo.insertOne({"StudentName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6f9cde8cc557214c0e0b") } > db.updateRecordDemo.insertOne({"StudentName":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbd6f9dde8cc557214c0e0c") }Display all documents from a collection with the help of find() method −> db.updateRecordDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cbd6f95de8cc557214c0e0a"), "StudentName" : "Larry" } { "_id" : ObjectId("5cbd6f9cde8cc557214c0e0b"), "StudentName" : "David" } { "_id" : ObjectId("5cbd6f9dde8cc557214c0e0c"), "StudentName" : "Mike" }Following is the query to update record in ... Read More

Exact count of all rows in MySQL database?

Samual Sam
Updated on 30-Jul-2019 22:30:25
To exactly count all rows, you need to use the aggregate function COUNT(*). The syntax is as follows −select count(*) as anyAliasName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CountAllRowsDemo    -> (    -> Id int,    -> Name varchar(10),    -> Age int    -> ); Query OK, 0 rows affected (1.49 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into CountAllRowsDemo values(1, 'John', 23); Query OK, 1 row affected (0.15 ... Read More

Duration plusDays() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25
An immutable copy of a duration where some days are added to it can be obtained using the plusDays() method in the Duration class in Java. This method requires a single parameter i.e. the number of days to be added and it returns the duration with the added days.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofDays(5); System.out.println("The duration is: " + d); ... Read More

Add a value to Septet class in JavaTuples

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
The addAtX() method is used to add value to the Septet Tuple. The index can be set here with the X i.e. the place where the value gets added.Let us first see what we need to work with JavaTuples. To work with Septet class in JavaTuples, you need to import the following package −import org.javatuples.Septet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Septet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example ... Read More

Rename Root @ localhost username in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
The syntax is as follows to rename Root @localhostUPDATE MySQL.user SET user = ‘yourNewRootName’ WHERE user = 'root';To understand the above concept, let us check all the user names and host. The query is as followsmysql> select user, host from MySQL.user;The following is the output+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Manish           | %         | | User2            | %       ... Read More
Advertisements