C++ Program to Implement Graham Scan Algorithm to Find the Convex Hull

Nitya Raut
Updated on 30-Jul-2019 22:30:25
Convex hull is the minimum closed area which can cover all given data points.Graham's Scan algorithm will find the corner points of the convex hull. In this algorithm, at first the lowest point is chosen. That point is the starting point of the convex hull. Remaining n-1 vertices are sorted based on the anti-clock wise direction from the start point. If two or more points are forming same angle, then remove all points of same angle except the farthest point from start.From the remaining points, push them into the stack. And remove items from stack one by one, when orientation ... Read More

Querying array elements with MongoDB?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25
MongoDB is better when you are querying array elements. Let us use the following syntax for querying array elements −db.yourCollectionName.find({yourArrayFieldName:"yourValue"}).pretty();The above syntax will return all those documents which have the value “yourValue” in an array field.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.queryArrayElementsDemo.insertOne({    ... "StudentName":"John", "StudentFavouriteSubject":["C", "Java"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90c0354afe5c1d2279d694") } > db.queryArrayElementsDemo.insertOne({ "StudentName":"Carol", "StudentFavouriteSubject":["C", "C++"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c90c0434afe5c1d2279d695") } > db.queryArrayElementsDemo.insertOne({ "StudentName":"David", "StudentFavouriteSubject":["MongoDB", "Java"]}); {    "acknowledged" : ... Read More

The containsAll() method of AbstractSequentialList in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25
The containsAll() method of the AbstractSequentialList checks for all the elements in this collection. It returns TRUE if all this collection contains all the elements in the specified collection i.e. if the two collections are same.The syntax is as follows:public boolean containsAll(Collection c)Here, c is the collection to be checkedTo work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList containsAll() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();   ... Read More

Operator Precedence and Associativity in C

Nancy Den
Updated on 30-Jul-2019 22:30:25
Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has a higher precedence than the addition operator.For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will ... Read More

How to handle right to left swipe gestures?

Nitya Raut
Updated on 30-Jul-2019 22:30:25
This example demonstrate about How to handle right to left swipe gesturesStep 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 button view to handle swapsStep 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import ... Read More

Java Program to generate random number array within a range and get min and max value

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
At first, create a double array −double[] val = new double[10];Now, generate and display random numbers in a loop that loops until the length of the above array. We have used nextInt here for random numbers −for (int i = 0; i < val.length; i++) {    val[i] = new Random().nextInt(100);    System.out.println(val[i]); }Now, get the min and max values. Compare each value of the random array with the MIN and MAX values −double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (int i = 0; i < val.length; i++) {    if (val[i] < min)       min ... Read More

Implicit initialization of variables with 0 or 1 in C

Smita Kapse
Updated on 30-Jul-2019 22:30:25
We know that we need to declare variables before using it in our code. However, we variables can be assigned with 0 or 1 without declaration. In the following example we can see this.Example#include #include x, y, array[3]; // implicit initialization of some variables int main(i) {    //The argument i will hold 1    int index;    printf("x = %d, y = %d\n\n", x, y);    for(index = 0; index < 3; index++)       printf("Array[%d] = %d\n", i, array[i]);       printf("The value of i : %d", i); }Outputx = 0, y = 0 ... Read More

How to write an empty function in Python?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
In python, we can write an empty function or statements by using the ‘pass” statement. Writing a pass statement does nothing and is simply used to avoid compile errors while writing an empty function.Empty function in python: #Empty function in Python def empty_func(): passAbove code statements are little different than other popular programming languages like C, C++ or Java.#An empty function in C/C++/Java void func() { }Empty loop in PythonWe can write an empty loop, using “pass” statement -#Empty loop in Python condition = True while (condition == True):    passSimilarly we can empty conditional statement (if/else) using “pass” statement ... Read More

Can anyone suggest how to pass time the best possible way?

Hansika Rani
Updated on 30-Jul-2019 22:30:25
In this digital world passing time is very easy. There are many possible ways to pass time and it is not necessary that these possible ways are useful ways.You can get hooked up to your Television set where you have hundreds of channels. Watch movies on Netflix, Amazon Prime, Hot star etc., This is the most common pass time for lazy people in India.Here I suggest some good ideas to pass time in useful ways and this will not take more than 2-3 hours a day.Learn some new arts. Dancing, music, painting etc., Get into physical activities like swimming, cycling, ... Read More

Assembly program to transfer the status of switches

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
In this program we will see how to transfer the switch values from one port to another using 8085 and 8255 chip.Problem Statement:Write 8085 Assembly language program for interfacing between 8085 and 8255. Here eight switches are connected at port A. Transfer the status of these switches into port B. In port B the LEDs are connected.Discussion:The task is very simple. At first we have to setup the control word register of 8255 chip. After that we will take the input from port A, and send it to port B.The control word register is looks like this. It is holding ... Read More
Advertisements