A Binary Search Tree (BST) is a type of binary tree such that the left subtree has elements smaller than the root element and the right subtree has elements greater than the root element. In this article, our task is to search for an element in the given Binary Search Tree. Characteristics of Binary Search Tree Here are some of the characteristics of the BST: The left subtree of the BST has elements less than the root element. The right subtree of the BST has elements greater than the root ... Read More
In C++, a string constant also called a string literal is a fixed sequence of characters enclosed in double quotes (" "). For example: "This is a string" and it is used to read-only memory, and its value cannot be changed during the program. Defining C++ Strings ConstantsYou can define your own named string constants by using: String Literals The const keyword The #define preprocessor directive The constexpr keyword(in modern C++) Let us understand each type of String Constant in C++ by ... Read More
The #define, const, and Enum are all used for declaring constant values, but their behaviours and use cases differ. The #define is a preprocessor directive, which is used to define a macro (it is a string or name, in which you can assign a constant value), whereas const is a keyword with which you can declare a variable with a constant value. Whereas, an Enum is a special user-defined data type that represents a group of constants. In the following article, we will learn about all three in detail. Enumeration (Enum) An Enumeration (or Enum) is a user-defined data type ... Read More
Both and are the header files of C++ language. The .h extension was common in older, non-standard implementations like Turbo C++. The has been deprecated in modern C++ compilers and the became part of the C++ standard starting from the 1998 ANSI/ISO standard. The Header File The iostream.h header file was part of the early 1990s I/O streams library, developed at AT&T for use with early C++. At that time, C++ was not yet standardized. The purpose of this header file is used to perform the input-output operations. Example Following is an example of iostream.h as per ... Read More
The term "timer" is used to define the time based operations on hours, minutes, and seconds. Here, we can use the chrono library of C++ that helps to set the different timer operations like countdown, delayed, current time, etc. In this article, we will learn how to create a timer using C++. Timer Properties There are various properties to consider for building a timer in C++ program: Integer: int (milliseconds to wait until to run code). Boolean: bool (If this is true, it returns instantly, and run the code after specified ... Read More
Both scope resolution operator and 'this' pointer are used for different purposes in the C++ programs. The scope resolution operator is used to access static or class members whereas this pointer is used to access object members when there is a local variable with the same name. Scope Resolution Operator in C++ The concept of scope resolution operator (::) is used in Object-Oriented Programming (OOPs) and namespace standard that can used to access something belongs to a specific scope, such as a class or namespace. Syntax It's syntax is as follows: :: Example In this program, we use ... Read More
In C/C++, undefined behavior refers to unexpected program output. When we write any program based on C or C++, sometimes we do not get the output as expected. This may be due to undefined behavior which cannot be predictable. For reference, sometimes it will show correct result, sometimes it will give the wrong result, and sometimes it may crash. Common Examples of Undefined Behavior in C/C++ Now, we have list of example that shows undefined behavior in C/C++ programs: Divide by Zero Using Uninitialized Variable NULL Pointer ... Read More
The sprintf() function of C library equivalent to C++ that is used to create strings with a specified format like custom text with numbers or names. In C++, we can perform the same operation as in C with the help of ostringstream.C++ std::ostringstreamThe ostringstream is known for the output string stream and is defined under header file. This is used to build the string by writing some text into it. Syntax i. Following is the basic syntax of sprint() function in C: int sprintf(char *str, const char *format, ...); ii. Here, we show the syntax of C++ function ... Read More
In this article, we will learn to use the collect() method in the Stream API in Java 9. Java Stream API collect() Method In Java, the collect() method in the Stream API collects all objects from a stream object and stores them in a type of collection. The user has to provide what type of collection the results can be stored. We specify the collection type using the Collectors Enum. There are different types, and different operations can be present in the Collectors Enum. Syntax The following is the syntax for the collect() method declaration: R collect(Collector
In this article, we will learn about the EnumMap and HashMap in Java. First, we will know about EnumMap, the syntax of EnumMap, and an example after that will learn about HashMap, the syntax of HashMap, and an example. At the end, we will see a table showing the difference between EnumMap and HashMap. What is EnumMap? EnumMap is introduced in JDK 5. It is designed to use an Enum as a key in the Map. It is an implementation of the Map interface. All of the keys in the EnumMap should be of the same enum type. Keys cannot be ... Read More