C++ Program for Gnome Sort

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

499 Views

Here we will see how the gnome sort works. This is another sorting algorithm. In this approach if the list is already sorted it will take O(n) time. So best case time complexity is O(n). But average case and worst case complexity is O(n^2). Now let us see the algorithm to get the idea about this sorting technique.AlgorithmgnomeSort(arr, n)begin    index := 0    while index < n, do       if index is 0, then          index := index + 1       end if       if arr[index] >= arr[index -1], then ... Read More

When Are Constructors Called in C++

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

661 Views

Here we will see, when constructors are called. Here constructors are of different types. Global, local, static local, dynamic.For the global object, the constructors are called before entering into the main function.Example#include using namespace std; class MyClass {    public:       MyClass() {          cout

Hiding All Overloaded Methods in Base Class in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

574 Views

In C++, we can use the function overloading techniques. But if some base class has one method in overloaded form (different function signature with the same name), and the derived class redefines one of the function which is present inside the base, then all of the overloaded version of that function will be hidden from the derived class.Let us see one example to get the clear idea.Example#include using namespace std; class MyBaseClass {    public:       void my_function() {          cout

Return Result Sets in JDBC

Rishi Raj
Updated on 30-Jul-2019 22:30:26

1K+ Views

Yes, just like any other objects in Java we can pass a ResultSet object as a parameter to a method and, return it from a method.Let us create a table with name MyPlayers in MySQL database using CREATE statement as shown below −CREATE TABLE MyPlayers(    ID INT,    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255),    PRIMARY KEY (ID) );Now, we will insert 7 records in MyPlayers table using INSERT statements −insert into MyPlayers values(1, 'Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into MyPlayers values(2, 'Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into MyPlayers values(3, 'Kumara', 'Sangakkara', ... Read More

Find All Documents with Two Specific IDs in an Array of Objects in MongoDB

Anvi Jain
Updated on 30-Jul-2019 22:30:26

128 Views

You can use $and operator for this. Let us first create a collection with documents −> db.twoSpecificIdsDemo.insertOne( ...   { ...      PlayerId:1, ...      "PlayerDetails": [{ ...         id: 100, ...         "PlayerName":"Chris" ...      }, { ...         id: 101, ...         "PlayerName":"Sam" ...      }, { ...         id: 102, ...         "PlayerName":"Robert" ...      }, { ...         id: 103, ...         "PlayerName":"Carol" ...      }] ... Read More

Prevent Collapse of Nodes and Child Nodes in JTree with Java

Chandu yadav
Updated on 30-Jul-2019 22:30:26

443 Views

Yes, we can prevent the collapse of nodes and child nodes in a JTree using setExpandedState() method. This method sets the expanded state of this JTree.If state istrue, all parents of path and path are marked asexpanded.The following is an example that prevents the collapse of nodes and child nodes in a JTree with Java −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.text.Position; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Project");       DefaultMutableTreeNode ... Read More

Set Font for Text in JTextPane with Java

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

1K+ Views

Use the Font class to set font for text. Let us first create JTextPane component −JTextPane textPane = new JTextPane();Now, set the font with the Font class setFont() method −Font font = new Font("Serif", Font.ITALIC, 18); textPane.setFont(font);The following is an example to set font for text −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class SwingDemo {    public static void main(String args[]) throws BadLocationException {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       ... Read More

Delete Entry in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

123 Views

You can use delete command −delete from yourTableName where yourColumnName='\\';Let us first create a table −mysql> create table DemoTable    (    FolderName varchar(100)    ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values("????"); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values("\\"); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+ | FolderName | +------------+ | ???? | | \ ... Read More

Group By a Column in Another MySQL Table

Rama Giri
Updated on 30-Jul-2019 22:30:26

325 Views

For this, you can use CREATE TABLE AS SELECT statement. Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> CountryName varchar(20)    -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(CountryName) values('US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1(CountryName) values('UK'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1(CountryName) values('AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1(CountryName) values('UK'); Query OK, ... Read More

C++ Program for Largest K-Digit Number Divisible by X

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

149 Views

In this problem we will try to find largest K-digit number, that will be divisible by X. To do this task we will take the largest K digit number by this formula ((10^k) – 1). Then check whether the number is divisible by X or not, if not, we will get the exact number by using this formula.𝑚𝑎𝑥−(𝑚𝑎𝑥 𝑚𝑜𝑑 𝑋)One example is like a 5-digit number, that is divisible by 29. So the largest 5-digit number is 99999. This is not divisible by 29. Now by applying the formula we will get −99999−(99999 𝑚𝑜𝑑 29)=99999−7=99992The number 99992 is divisible by ... Read More

Advertisements