C++ Program to Search for an Element in a Binary Search Tree

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
In this program we need to. Implement binary search to find the existence of a search sequence in a binary search tree. The worst case time complexity of Binary search is O(n) but for the average case O(log(n)).AlgorithmBegin    Construct binary search tree for the given unsorted data array by inserting data into tree one by one.    Take the input of data to be searched in the BST.    Now starting from the root node, compare the data with data part of the node.    if data < temp->d, move the temp pointer to the left child.    if ... Read More

Retrieve only the queried element in an object array in MongoDB collection?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25
You can use projection operator $elemMatch to filter in queried element in an object array in MongoDB collection. To retrieve only the queried element in an object array in MongoDB, let us first create a collection with documents object array.The query is as follows:> db.objectArray.insert({"Persons":[    {"PersonName":"Adam", "PersonSalary":25000}, {"PersonName":"Larry", "PersonSalary":27000    }]});    WriteResult({ "nInserted" : 1 }) > db.objectArray.insert({"Persons":[    {"PersonName":"David", "PersonSalary":32000}, {"PersonName":"Carol", "PersonSalary":77000    }]});    WriteResult({ "nInserted" : 1 })Now you can display all the documents with the help of find(). The query is as follows:> db.objectArray.find().pretty();The following is the output:{    "_id" : ObjectId("5c6bfadc68174aae23f5ef53"),    "Persons" ... Read More

How to use <jsp:setProperty> action in JSP?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
The setProperty action sets the properties of a Bean. The Bean must have been previously defined before this action. There are two basic ways to use the setProperty action −You can use jsp:setProperty after, but outside of a jsp:useBean element, as given below − ... In this case, the jsp:setProperty is executed regardless of whether a new bean was instantiated or an existing bean was found.A second context in which jsp:setProperty can appear is inside the body of a jsp:useBean element, as given below − ... Here, the jsp:setProperty is executed only if ... Read More

How to format date in JSP?

Samual Sam
Updated on 30-Jul-2019 22:30:25
The tag is used to format dates in a variety of ways.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultValueDate value to displayYesNonetypeDATE, TIME, or BOTHNodatedateStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTNodefaulttimeStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTNodefaultpatternCustom formatting patternNoNonetimeZoneTime zone of the displayed dateNoDefault time zonevarName of the variable to store the formatted dateNoPrint to pagescopeScope of the variable to store the formatted dateNopageThe pattern attribute is used to specify even more precise handling of the date −CodePurposeSampleGThe era designatorADyThe year2002MThe monthApril & 04dThe day of the month20hThe hour(12-hour time)12HThe hour(24-hour time)0mThe minute45sThe second52SThe millisecond970EThe day of the weekTuesdayDThe day of ... Read More

LocalDate getEra() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25
The era for a particular LocalDate can be obtained using the getEra() method in the LocalDate class in Java. This method requires no parameters and it returns the era applicable for the LocalDate.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDate ld = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld); System.out.println("The era is: " + ld.getEra()); } }OutputThe LocalDate is: 2019-02-14 The ... Read More

What is the setAtX() method of the Ennead Tuple in Java

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25
To set Ennead value in Java, you need to use the setAtX() method. Here, X represents the index wherein you need to set the value i.e. for index 1, use setAt1() method. Set the value as the parameter value of the method.Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following package −import org.javatuples.Ennead;Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the ... Read More

C++ Program to Implement Adjacency Matrix

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
The adjacency matrix of a graph is a square matrix of size V x V. The V is the number of vertices of the graph G. In this matrix in each side V vertices are marked. If the graph has some edges from i to j vertices, then in the adjacency matrix at ith row and jth column it will be 1 (or some non-zero value for weighted graph), otherwise that place will hold 0.The complexity of Adjacency Matrix representation:The adjacency matrix representation takes O(V2) amount of space while it is computed. When graph has maximum number of edges and ... Read More

Add DATE and TIME fields to get DATETIME field in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25
You can use CONCAT() function to set date and time fields to get DATETIME field.Let us create a demo tablemysql> create table getDateTimeFieldsDemo -> ( -> ShippingDate date, -> ShippingTime time, -> Shippingdatetime datetime -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into getDateTimeFieldsDemo(ShippingDate, ShippingTime) values('2018-01-21', '09:45:34'); Query OK, 1 row affected (0.16 sec) mysql> insert into getDateTimeFieldsDemo(ShippingDate, ShippingTime) values('2013-07-26', '13:21:20'); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Read file line by line using C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
This is a C++ program to read file line by line.Inputtpoint.txt is having initial content as “Tutorials point.”OutputTutorials point.AlgorithmBegin    Create an object newfile against the class fstream.    Call open() method to open a file “tpoint.txt” to perform write operation using object newfile.    If file is open then       Input a string “Tutorials point" in the tpoint.txt file.       Close the file object newfile using close() method.    Call open() method to open a file “tpoint.txt” to perform read operation using object newfile.    If file is open then       Declare a ... Read More

Stack Unwinding in C++

Nancy Den
Updated on 30-Jul-2019 22:30:25
Here we will see what is the meaning of stack unwinding. When we call some functions, it stores the address into call stack, and after coming back from the functions, pops out the address to start the work where it was left of.The stack unwinding is a process where the function call stack entries are removed at runtime. To remove stack elements, we can use exceptions. If an exception is thrown from the inner function, then all of the entries of the stack is removed, and return to the main invoker function.Let us see the effect of stack unwinding through ... Read More