Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2749 of 3366
348 Views
A dynamic 2D array is basically an array of pointers to arrays. Here is a diagram of a 2D array with dimenation 3 x 4.AlgorithmBegin Declare dimension of the array. Dynamic allocate 2D array a[][] using new. Fill the array with the elements. Print the array. Clear the memory by deleting it. EndExample Code Live Demo#include using namespace std; int main() { int B = 4; int A = 5; int** a = new int*[B]; for(int i = 0; i < B; ++i) a[i] = new int[A]; ... Read More
207 Views
In C++, it is faster to process a sorted array than an unsorted array due to some reasons related to algorithm efficiency and data access patterns. In this article, we see why this is the case and how sorting can improve performance of array processing. First of all, let see an example of processing time of a sorted and unsorted array. Processing Time: Sorted vs Unsorted Array In the example code below, we have used library of C++ STL to measure the time taken to process an unsorted array and a sorted array. The code counts how many ... Read More
3K+ Views
Bit array is used to store true/false or yes/no type of values in very less memory. In this article, we will see how to create and use a bit array in C++. What is Bit Array? Bit array is a special array where each element can hold only 0 or 1. Instead of using a full byte (8 bits) for each boolean value, a bit array stores multiple values using just one bit each. Meaning, in a normal array of bool values, each value takes at least one byte. But in bit array, we store 8 values in one ... Read More
652 Views
In this article, we will learn what is graph structured stack and how to implement it in a C++ program. What is Graph Structured Stack? Graph structured stack is a directed acyclic graph, where each directed path represents a stack. In this types of stack, the flow of execution is not linear like a traditional stack, instead the flow is represented using a graph structure. Each node in the graph can represent a function call or a state, and the edges define possible transitions or calls. This type of stacks are useful in advanced control flow handling like backtracking, ... Read More
2K+ Views
DAG stands for Directed Acyclic Graph. It is a special type of graph where all edges are directed and there are no cyclic connections of edges. In this article, we will discuss how to check whether a graph is a DAG using Kahn’s algorithm (BFS based topological sorting). What is DAG? A DAG is a directed graph with no cycles. That means in this type graph it is not possible to start from any node and follow a sequence of edges such that you will return back to the starting node. DAGs are commonly used in applications like task ... Read More
115 Views
The day of the year for a particular LocalDateTime can be obtained using the getDayOfYear() method in the LocalDateTime class in Java. This method requires no parameters and it returns the day of the year which can be in the range of 1 to 365 and also 366 for leap years.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:30:15"); System.out.println("The LocalDateTime is: " + ldt); System.out.println("The day of the year is: " + ... Read More
157 Views
The hour of the day for a particular LocalDateTime can be obtained using the getHour() method in the LocalDateTime class in Java. This method requires no parameters and it returns the hour of the day which can range from 0 to 23.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35"); System.out.println("The LocalDateTime is: " + ldt); System.out.println("The hour is: " + ldt.getHour()); } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The hour is: 15Now let ... Read More
661 Views
The year for a particular LocalDateTime can be obtained using the getYear() method in the LocalDateTime class in Java. This method requires no parameters and it returns the year which can range from MIN_YEAR to MAX_YEAR.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35"); System.out.println("The LocalDateTime is: " + ldt); System.out.println("The year is: " + ldt.getYear()); } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The year is: 2019Now let us understand the above program.First the ... Read More
180 Views
The equality of two LocalDateTime objects can be determined using the equals() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object to be compared. Also it returns true if both the LocalDateTime objects are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30"); LocalDateTime ldt2 = LocalDateTime.parse("2019-02-18T23:15:30"); System.out.println("The LocalDateTime ldt1 is: " + ldt1); System.out.println("The LocalDateTime ldt2 is: " ... Read More
300 Views
An immutable copy of a LocalDateTime with the nanoseconds altered as required is done using the method withNano() in the LocalDateTime class in Java. This method requires a single parameter i.e. the nanosecond that is to be set in the LocalDateTime and it returns the LocalDateTime with the nanosecond altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main { public static void main(String[] args) { LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30"); System.out.println("The LocalDateTime is: " + ldt1); LocalDateTime ldt2 = ldt1.withNano(5); ... Read More