C++ Program to Implement Disjoint Set Data Structure

Smita Kapse
Updated on 30-Jul-2019 22:30:25

3K+ Views

Disjoint set is basically as group of sets where no item can be in more than one set. It supports union and find operation on subsets.Find(): It is used to find in which subset a particular element is in and returns the representative of that particular set.Union(): It merges two different subsets into a single subset and representative of one set becomes representative of other.Functions and pseudocodesBegin    Assume k is the element    makeset(k):       k.parent = k.    Find(x):    If k.parent == k       return k.    else    return Find(k.parent)    Union ... Read More

Sort Certain Values to the Top in MySQL

Samual Sam
Updated on 30-Jul-2019 22:30:25

257 Views

You need to use ORDER BY clause to sort. The syntax is as follows −SELECT *FROM yourTableName ORDER BY yourColumnName='yourValue' DESC, yourIdColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SortCertainValues    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> CountryName varchar(10),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.36 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into SortCertainValues(Name, CountryName) values('Adam', 'US'); Query OK, 1 row ... Read More

ShortBuffer Array Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

168 Views

A short array for the buffer can be obtained using the method array() in the class java.nio.ShortBuffer. If the returned array is modified, then the contents of the buffer are also similarly modified and vice versa. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ShortBuffer buffer = ShortBuffer.allocate(n);          buffer.put((short)12);          buffer.put((short)91); ... Read More

Clock tickMinutes Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

213 Views

The current ticking value in minutes can be obtained using the method tickMinutes() in the Clock Class in Java. This method requires a single parameter i.e. the time zone and it returns the current ticking value in minutes.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { ZoneId zId = ZoneId.of("Australia/Melbourne"); Clock c = Clock.tickMinutes(zId); System.out.println("The current ticking value in minutes is: " + c.instant()); ... Read More

AddAtX Method for Unit Class in Java Tuples

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

149 Views

The addAtX() method is used to add value to the 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 the Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Unit Class in Java Tuples, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport ... Read More

Check if Value Exists in a Comma-Separated List in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

12K+ Views

To check if value exists in a comma separated list, you can use FIND_IN_SET() function.The syntax is as followsSELECT *FROM yourTablename WHERE FIND_IN_SET(‘yourValue’, yourColumnName) > 0;Let us first create a table. The query to create a table is as followsmysql> create table existInCommaSeparatedList - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > Name varchar(200) - > ); Query OK, 0 rows affected (0.68 sec)Now you can insert some records in the table using insert command.The query is as followsmysql> insert into existInCommaSeparatedList(Name) values('John, ... Read More

Get Minute from LocalDateTime in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

65 Views

The minute of the hour for a particular LocalDateTime can be obtained using the getMinute() method in the LocalDateTime class in Java. This method requires no parameters and it returns the minute of the hour in the range of 0 to 59.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The minute is: " + ldt.getMinute());    } }OutputThe LocalDateTime is: 2019-02-18T23:15:30 The minute is: 15Now let ... Read More

ArrayBlockingQueue Iterator Method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

238 Views

The iterator() method of the ArrayBlockingQueue class returns an iterator over the elements in this queue in proper sequence.The syntax is as follows.public Iterator iterator()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement iterator() method of Java ArrayBlockingQueue class.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(10);       q.add(400);       q.add(450);       q.add(500);       q.add(550); ... Read More

Use take() in Android ArrayBlockingQueue

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

123 Views

Before getting into the example, we should know what arrayblockingqueue is, it travels FIFO manner and the first element going to live the longest period of time and last element of the queue going to live a short period of the time.This example demonstrates about How to use take() in android ArrayBlockingQueueStep 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 a text view to show ... Read More

Resolve Unknown Database in JDBC Error with Java MySQL

George John
Updated on 30-Jul-2019 22:30:25

9K+ Views

This type of error occurs if you select any database that does not exist in MySQL. Let us first display the error of unknown database in JDBC.The Java code is as follows. Here, we have set the database as ‘onlinebookstore’, which does not exist:import java.sql.Connection; import java.sql.DriverManager; public class UnknownDatabaseDemo {    public static void main(String[] args) {       String JdbcURL = "jdbc:mysql://localhost:3306/onlinebookstore?useSSL=false";       String Username = "root";       String password = "123456";       Connection con = null;       try {          con = DriverManager.getConnection(JdbcURL, Username, password); ... Read More

Advertisements