C++ Program to Check Whether Topological Sorting can be Performed in a Graph

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

427 Views

In a Directed Acyclic Graph, we can sort vertices in linear order using topological sort.Topological sort is only work on Directed Acyclic Graph. In a Directed Acyclic Graph (DAG), there can be more than one topological sort.In the following C++ program, we shall perform topological sort to check existence of a cycle in a graph.AlgorithmsFor function Topo_SortBegin    Define function Topo_Sort()       Declare x to the integer datatype, vstd[] of the Boolean array and Stack as a stack.          Pass them as parameter.       Initialize vstd[x] = true to mark the current node ... Read More

Regex to ignore a specific character in MongoDB?

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

744 Views

You can use regular expression along with $not operator to ignore a specific character and display rest of them. Let us first create a collection with documents −> db.regexDemo.insertOne({"CustomerId":"Customer#1234", "CustomerName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7428f8f9e6ff3eb0ce436") } > db.regexDemo.insertOne({"CustomerId":"Customer5678", "CustomerName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7429e8f9e6ff3eb0ce437") } > db.regexDemo.insertOne({"CustomerId":"Customer#777", "CustomerName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc742ae8f9e6ff3eb0ce438") } > db.regexDemo.insertOne({"CustomerId":"Customer777", "CustomerName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc742bc8f9e6ff3eb0ce439") }Following is the query to display all documents from a collection with the help of find() method −> db.regexDemo.find().pretty();This will produce the ... Read More

How to get this nodes’s parent in a JTree with Java?

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

549 Views

Let’s say we want the parent of a node, then use the getParent() method -node3.getFirstChild()You can also get the parent of child node. Here, “nine” is the child node −nine.getParent()The output is as follows displaying this node’s parent on Console −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Accessories (Product2 - P66779)");   ... Read More

How to add a field with static value to MongoDB find query?

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

436 Views

You can use $literal operator along with aggregate framework. Let us first create a collection with documents −> db.fieldWithStaticValue.insertOne({"Name":"Larry", "Age":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6554c7924bb85b3f48948") } > db.fieldWithStaticValue.insertOne({"Name":"Chris", "Age":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd655567924bb85b3f48949") } > db.fieldWithStaticValue.insertOne({"Name":"David", "Age":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd655607924bb85b3f4894a") }Following is the query to display all documents from a collection with the help of find() method −> db.fieldWithStaticValue.find();This will produce the following output −{ "_id" : ObjectId("5cd6554c7924bb85b3f48948"), "Name" : "Larry", "Age" : 24 } { "_id" : ObjectId("5cd655567924bb85b3f48949"), "Name" : "Chris", "Age" : 23 ... Read More

ctime() Function in C/C++

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

306 Views

The C library function char *ctime(const time_t *timer) returns a string representing the localtime based on the argument timer.The returned string has the following format − Www Mmm dd hh:mm:ss yyyy, where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.The syntax is like below −char *ctime(const time_t *timer)This function takes the pointer to a time_t, which is containing the calendar time. It returns a string containing date, time info in human readable format.Example Live Demo#include #include int main () {    time_t curtime;    time(&curtime); ... Read More

How to use an enum with switch case in Java?\

Venkata Sai
Updated on 30-Jul-2019 22:30:26

1K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }You can also define an enumeration with custom values to the constants declared. But you need to have an instance variable, a constructor and getter method to return values.Enum with switch caseLet us create an enum with 5 constants representing models of 5 different scoters with their prices as values, as shown below −enum Scoters { ... Read More

HTML DOM Input FileUpload form Property

Sharon Christine
Updated on 30-Jul-2019 22:30:26

76 Views

The HTML DOM input FileUpload form property returns the reference of the form which enclose the file upload input button.SyntaxFollowing is the syntax −object.formExampleLet us see an example of input FileUpload form property − Live Demo    body{       text-align:center;       background-color:#363946;       color:#fff;    }    form{       margin:2.5rem auto;    }    button{       background-color:#db133a;       border:none;       cursor:pointer;       padding:8px 16px;       color:#fff;       border-radius:5px;       font-size:1.05rem;    }    .show{     ... Read More

HTML DOM Input Email readOnly Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

48 Views

The HTML DOM Input Email readOnly property sets/returns whether Input Email can be modified or not.SyntaxFollowing is the syntax −Returning boolean value - true/falseinputEmailObject.readOnlySetting readOnlyto booleanValueinputEmailObject.readOnly = booleanValueBoolean ValuesHere, “booleanValue” can be the following −booleanValueDetailstrueIt defines that the input email field is readOnly.falseIt defines that the input email field is not readOnly and can be modified.ExampleLet us see an example of Input Email readOnly property − Live Demo Input Email readOnly    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: ... Read More

Print prime numbers with prime sum of digits in an array

Sunidhi Bansal
Updated on 30-Jul-2019 22:30:26

482 Views

Given with an array of elements and the task is to print those numbers whose digit sum is also prime and return -1 is not such digit exists in an arrayInput: arr[]={2, 4, 3, 19, 25, 6, 11, 12, 18, 7} Output : 2, 3, 25, 11, 12, 7Here, the given output is generated as it contains those additive numbers whose sum is also prime like − 2, 3, 7 are prime but 25(2+5=7), 11(1+1=2), 12(1+2=3) are also prime whereas numbers like 19(1+9=10) are not prime.AlgorithmSTART Step 1 -> Take array of int with values Step 2 -> declare start ... Read More

Java Program to convert Stream to List

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

143 Views

Declare and initialize an Integer array:Integer[] arr = {50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000};Now, create a stream with the above elements:Stream stream = Arrays.stream(arr);To convert the above stream to list, use Collectors.toList():stream.collect(Collectors.toList()The following is an example to convert Stream to List:Exampleimport java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo {    public static void main(String[] args) {       Integer[] arr = {50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000};       Stream stream = Arrays.stream(arr);       System.out.println("Stream = "+stream.collect(Collectors.toList()));    } }OutputStream = [50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000]

Advertisements