C qsort() vs C++ sort()

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

373 Views

Here we will see what are the differences between qsort() in C, and sort() in C++.The C provides qsort() function, that can be used for sorting an array. The function arguments and syntax is like below.void qsort(void *base, size_t num, size_t size, int (*comparator) (const void*, const void*));This function takes the base address of that array, the number of elements of that array. Size of each item in the array, and a comparator function.The C++ provides sort() function. This is present inside C++ STL. The arguments and syntax is like below.void sort(T first, T last, Compare c);Here the order of ... Read More

How to use POSIX semaphores in C language

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

2K+ Views

The semaphore is a concept of process or thread synchronization. Here we will see how to use the semaphores in real programs.In Linux system, we can get the POSIX semaphore library. To use it, we have to include semaphores.h library. We have to compile the code using the following options.gcc program_name.c –lpthread -lrtWe can use sem_wait() to lock or wait. And sem_post() to release the lock. The semaphore initializes sem_init() or sem_open() for the Inter-Process Communication (IPC).Example#include #include #include #include sem_t mutex; void* thread(void* arg) { //function which act like thread    sem_wait(&mutex); //wait state   ... Read More

How to Schedule Notification in Android?

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

385 Views

This example demonstrate about How to schedule notification in android.Step 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. Step 3 − Add the following code to res/menu/main_menu.xml.             Step 4 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.AlarmManager ; import android.app.Notification ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.os.Bundle ; import android.os.SystemClock ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; ... Read More

How to retrieve a nested object in MongoDB?

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

797 Views

To retrieve a nested object in MongoDB, use $ operator. Let us first create a collection with documents −> db.queryNestedObject.insertOne( ...    { ...       "StudentName" : "James", ...       "StudentSubjectScore" : [ ...          {"StudentMongoDBScore":98}, ...          {"StudentCScore":92}, ...          {"StudentJavaScore":91} ...       ] ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccf49a9dceb9a92e6aa1962") }Following is the query to display all documents from a collection with the help of find() method −> db.queryNestedObject.find().pretty();This will produce the following output −{   ... Read More

Does Java support multi-dimensional Arrays?

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

401 Views

No, Java does not support multi-dimensional arrays.Java supports arrays of arrays.In Java, a two-dimensional array is nothing but, an array of one-dimensional arrays.                  int[][] arr = new int[2][4];The expression arr[i] selects the one-dimensional array and the expression arr[i][j] selects the element from that array.Array indices in each dimension range from zero to "length". Where length is the array length in the given dimension. There is no array assignment operator. The number of dimensions and the size of each dimension is fixed once the array has been allocated.

How to create a GridLayout with rows and columns in Java?

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

524 Views

While creating a GridLayout, you need to set the rows and columns as parenthesis. A GridLayout is used to create a layout the specified number of rows and columns.Let’s say we have a GridLayout, with 1 row and 4 columns −GridLayout layout = new GridLayout(1, 4);The following is an example to create a GridLayout with rows and columns −Examplepackage my; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new ... Read More

Is there any way to see the MongoDB results in a better format?

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

48 Views

Yes, you can use the findOne(). Following is the syntax −db.yourCollectionName.findOne();You can use toArray() as well −db.yourCollectionName.find().toArray();Let us first create a collection with documents −> db.betterFormatDemo.insertOne({"StudentName":"Adam Smith", "StudentScores":[98, 67, 89]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7ab826d78f205348bc640") } > db.betterFormatDemo.insertOne({"StudentName":"John Doe", "StudentScores":[67, 89, 56]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7ab936d78f205348bc641") } > db.betterFormatDemo.insertOne({"StudentName":"Sam Williams", "StudentScores":[45, 43, 33]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7aba76d78f205348bc642") }Following is the query to display all documents from a collection with the help of find() method −> db.betterFormatDemo.find();This will produce the following output −{ "_id" : ObjectId("5cd7ab826d78f205348bc640"), "StudentName" ... Read More

regex_error in C++

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

158 Views

The regex library has different methods and features related to regular expressions. Here we will see some regex_errors. These are also present at regex library. During executing some regular expressions, we get some errors. That errors are mentioned here.FlagsErrorserror_collateIn the Regex, the names having invalid collation.error_ctypeIn the Regex, there is an invalid character class name.error_stackNot enough memory to determine regex can be matched or not.error_spaceConvert into Finite State Machine, when memory is insufficienterror_badrepeatThe string has repeat specifier ( *?+{) that was not preceded by a valid regular expression.error_complexityThe complexity of an attempted match against a regex exceeded a pre-set levelerror_rangeContaining ... Read More

How to write your own header file in C?\

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

14K+ Views

Here we will see how to create own header file using C. To make a header file, we have to create one file with a name, and extension should be (*.h). In that function there will be no main() function. In that file, we can put some variables, some functions etc.To use that header file, it should be present at the same directory, where the program is located. Now using #include we have to put the header file name. The name will be inside double quotes. Include syntax will be look like this.#include”header_file.h”Let us see one program to get the ... Read More

Java Connection getAutoCommit() method with example

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

486 Views

If you commit a database, it saves all the changes that have been done till that particular point. By default, some databases commits/saves the changes done automatically. You can turn off/on the auto-commit using the setAutoCommit() method of the Connection interface.The getAutocommit() method of the Connection interface is used to get the current value of the auto-commit in this connection.To get the auto-commit value −Register the driver using the registerDriver() method of the DriverManager class as −//Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get the connection using the getConnection() method of the DriverManager class as −//Getting the connection String url = "jdbc:mysql://localhost/mydatabase"; Connection con ... Read More

Advertisements