Programming Articles - Page 2716 of 3366

C++ Program to Implement AVL Tree

Aman Kumar
Updated on 30-May-2025 18:42:56

24K+ Views

In this article, we will demonstrate how to implement an AVL tree. An AVL tree is a self-balancing binary search tree in which the height difference between the left and right subtrees (balance factor) of any node cannot exceed one. AVL TREE Following are the points of an AVL tree − Tree rotation is a way to change the structure of an AVL tree without changing the order of the elements. It helps keep the tree balanced by moving one node up and one node down. Tree rotations are mainly used ... Read More

DoubleStream min() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

134 Views

The min() method of the DoubleStream class returns an OptionalDouble describing the minimum element of this stream, or an empty OptionalDouble if this stream is empty.The syntax is as follows:OptionalDoublemin()Here, OptionalDouble is a container object which may or may not contain a double valueTo use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create a DoubleStream and add elements to the stream:DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);Get the maximum element from the DoubleStream:OptionalDouble res = doubleStream.max();The following is an example to implement DoubleStream min() method in Java:Example Live Demoimport java.util.OptionalDouble; import java.util.stream.DoubleStream; public class Demo {    public ... Read More

Difference between ++*p, *p++ and *++p in c++

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

In this section we will see what are the differences between *ptr++, *++ptr and ++*ptr in C++.Here we will see the precedence of postfix++ and prefix++ in C or C++. The precedence of prefix ++ or -- has higher priority than dereference operator ‘*’ and postfix ++ or -- has priority higher than both prefix ++ and dereference operator ‘*’.When ptr is a pointer, then *ptr++ indicates *(ptr++) and ++*prt refers ++(*ptr)Example Code Live Demo#include using namespace std; int main() { char arr[] = "Hello World"; char *ptr = arr; ++*ptr; cout

Implementing own Hash Table with Open Addressing Linear Probing in C++

Samual Sam
Updated on 30-Jul-2019 22:30:25

1K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.Linear probing is a collision resolving technique in Open Addressed Hash tables. In this method, each cell of a hash table stores a single key–value pair. If a collision is occurred by mapping a new key to a cell of the hash table that is already occupied by another key. This method searches the table for the following closest free location and inserts the ... Read More

LongStream min() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

148 Views

The min() method of the LongStream class in Java returns an OptionalLong describing the minimum element of this stream, or an empty optional if this stream is empty.The syntax is as follows:OptionalLong min()Here, OptionalLong is a container object which may or may not contain a long value.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;The following is an example to implement LongStream min() method in Java. The isPresent() method of the OptionalLong class returns true if the value is present:Example Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {     ... Read More

IntStream sequential() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

452 Views

The sequential() method of the IntStream class in Java is used to return a sequential IntStream. The syntax is as follows:IntStream sequential()First, create an IntStream and elements in a range using the range() method:IntStream intStream1 = IntStream.range(11, 21);Now, for a sequential IntStream, use the sequential() method like this:IntStream intStream2 = intStream1.sequential();The following is an example to implement IntStream sequential() method in Java:Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream1 = IntStream.range(11, 21);       IntStream intStream2 = intStream1.sequential();       intStream2.forEach(System.out::println);    } }Output11 12 ... Read More

C++ Program to Implement Hash Tables with Quadratic Probing

Aman Kumar
Updated on 28-May-2025 16:51:57

2K+ Views

Hash Table A hash table is a data structure which is used to store key-value pairs and uses hash function to compute an index into an array of buckets or slots in which an element will be inserted or searched in average-case constant time. Why are Collision a Problem? A collision is a problem because even a perfect hash function can generate the same index for multiple keys, causing a collision. To resolve these, we use techniques like − Chaining Linear Probing Quadratic Probing Quadratic Probing ... Read More

Variable number of arguments in C++

Aman Kumar
Updated on 28-May-2025 16:51:15

7K+ Views

Sometimes, you may come across a scenario where you want to have a function that can take a variable number of arguments, i.e., parameters, instead of a predefined number of parameters. The C/C++ programming language provides a solution for this scenario, and you are allowed to define a function that can accept a variable number of parameters based on your requirement. Following are the ways to use variable number of arguments − C-style Variadic Functions (with stdarg.h) C-style variadic functions in C++ use stdarg.h macros like va_start, va_arg, and va_end to handle a variable number of arguments at runtime. int ... Read More

Heap overflow and Stack overflow in C

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

6K+ Views

Heap OverflowHeap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables.Heap overflow occurs when −A) If we allocate dynamic large number of variables −int main() {    float *ptr = (int *)malloc(sizeof(float)*1000000.0)); }B) If we continuously allocate memory and do not free after using it.int main() {    for (int i=0; i

How do I clear the cin buffer in C++?

Aman Kumar
Updated on 06-Jun-2025 19:39:15

2K+ Views

Before knowing the solution to clearing the cin buffer in C++, let us first see what the buffer is in C++. What is The Buffer in C++ A buffer is a temporary storage area that holds data while standard I/O devices are in use. In C++, a stream also work as a buffer. When a key is pressed, the input is not immediately sent to the program; instead, it is stored in a buffer. The operating system keeps this data in the buffer until the program is allocated time to process it. Why We Clear The cin Buffer in C++ ... Read More

Advertisements