Articles on Trending Technologies

Technical articles with clear explanations and examples

How to reverse an Array using STL in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Here we will see how to reverse an array using STL functions in C++. So if the array is like A = [10, 20, 30, 40, 50, 60], then the output will be B = [60, 50, 40, 30, 20, 10]. To reverse we have one function called reverse() present in the header file . The code is like below −Example#include #include using namespace std; int main() {    int arr[] = {10, 20, 30, 40, 50, 60};    int n = sizeof(arr) / sizeof(arr[0]);    cout

Read More

How to create a shallow copy of Hashtable in C#?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 390 Views

To create a shallow copy of Hashtable, the code is as follows −Exampleusing System; using System.Collections; public class Demo {    public static void Main() {       Hashtable hash = new Hashtable();       hash.Add("1", "AB");       hash.Add("2", "BC");       hash.Add("3", "DE");       hash.Add("4", "EF");       hash.Add("5", "GH");       hash.Add("6", "IJ");       hash.Add("7", "KL");       hash.Add("8", "MN");       hash.Add("9", "OP");       hash.Add("10", "QR");       Console.WriteLine("Hashtable elements...");       foreach(DictionaryEntry d in hash) {       ...

Read More

How to traverse a C++ set in reverse direction?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a set, then we have to traverse the set in reverse direction. So if the set is like S = [10, 15, 26, 30, 35, 40, 48, 87, 98], then the output will be: 98 87 48 40 35 30 26 15 10.To traverse in reverse order, we can use the reverse_iterator. Here we will use the rbegin() and rend() function to get the begin and end of the reverse iterator.Example#include #include using namespace std; int main() {    int arr[] = {10, 15, 26, 30, 35, 40, 48, 87, 98};    set my_set(arr, arr + sizeof(arr) / sizeof(arr[0]));    set::iterator it;    cout

Read More

Validate IP Address in C++

Ajay yadav
Ajay yadav
Updated on 11-Mar-2026 3K+ Views

This article is serving the purpose of validating the correct IP (internet protocol) address by virtue of C++ code programming. The IP address is a 32-bit dot-decimal-notation, broken into four decimal numbers segments ranging from 0 to 255. Furthermore, these numbers are separated by dots consecutively. The IP address serves the purpose of identifying a host machine in the network in a unique manner in order to establish a connection among them.So, in order to validate the correct IP address input from the user-end, the following algorithm briefs how exactly the code sequence is materialized to identify the correct IP ...

Read More

How to use getline() in C++ when there are blank lines in input?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

In C++, we use the getline() function to read lines from stream. It takes input until the enter button is pressed, or user given delimiter is given. Here we will see how to take the new line character as input using the getline() function. Let us see the following implementation to get the idea.Example#include using namespace std; int main() {    string str;    int term = 4;    while (term--) {       getline(cin, str);       while (str.length()==0 )       getline(cin, str);       cout

Read More

Chrono in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 627 Views

In this section we will see what is the Chrono library in C++. This Chrono library is used for date and time. Timers and clocks are different in different systems. So if we want to improve time over precision we can use this library.In this library, it provides precision-neutral concept, by separating the durations and point of time.The duration objects are used to express time span by means of a count like minute, two hours or ten minutes. For example, 30 seconds is represented by a duration consisting of 30 ticks of unit of 1 seconds.Example#include #include using ...

Read More

Final cell position in the matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 305 Views

Suppose we have a set of commands as a string, the string will have four different letters for four directions. U for up, D for down, L for left and R for right. We also have initial cell position (x, y). Find the final cell position of the object in the matrix after following the given commands. We will assume that the final cell position is present in the matrix. Suppose the command string is like “DDLRULL”, initial position is (3, 4). The final position is (1, 5).The approach is simple, count the number of up, down, left and right ...

Read More

Find a distinct pair (x, y) in given range such that x divides y in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 225 Views

Here we will see one interesting problem, we will find a pair (x, y), where x and y are in range so l

Read More

Find a Fixed Point (Value equal to index) in a given array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 403 Views

Here we will see how to find fixed point in a given array. In array one element will be denoted as fixed point if the value is same as its index. This program will return the value if any, otherwise return -1. The array can hold negative numbers also. And the data elements are sorted.Here we will use binary search approach to solve this problem in O(log n) time. At first we will check whether the middle element is fixed point or not, if yes, then return it, if not, then there will be two situations, if the index of ...

Read More

Find a Fixed Point in an array with duplicates allowed in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 283 Views

Here we will see how to find fixed point in a given array. In array one element will be denoted as fixed point if the value is same as its index. This program will return the value if any, otherwise return -1. The array can hold negative numbers also. And the data elements are sorted. Here duplicate elements are allowed in the array.Here we will use binary search approach to solve this problem in O(log n) time. But we need some modification, if the normal binary search is used, then it may fail for duplicate elements. To check left, we ...

Read More
Showing 28661–28670 of 61,299 articles
Advertisements