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 1751 of 3366
269 Views
Suppose we have one postorder traversal of a binary search tree; we have to find the binary search tree from it.So, if the input is like [6, 12, 10, 55, 45, 15], then the output willTo solve this, we will follow these steps −Define a function solve() . This will take postordern := size of postorderroot := make a new tree node with last element of postorderstk := a stackinsert root into stki := n - 2while i >= 0, dox := make a new node with value postorder[i]while stk is not empty and postorder[i] < value of top of ... Read More
666 Views
Suppose we have the inorder and postorder traversal sequence of a binary tree. We have to generate the tree from these sequences. So if the postorder and inorder sequences are [9, 15, 7, 20, 3] and [9, 3, 15, 20, 7], then the tree will be −Let us see the steps −Define a method build_tree(), this will take inorder, postorder −If inorder list is not empty −root := make a tree node with the last value of postorder, then delete that elementind := index of root data in inorder listright of root := build_tree(inorder from index ind to end, postorder)left ... Read More
298 Views
Suppose we have the postorder traversal sequence of a binary search tree. We have to generate the tree from these sequences. So, if the postorder sequences is [9, 15, 7, 20, 3], then the tree will be −To form a tree we need inorder traversal also, but for binary search tree, the inorder traversal will be in the sorted form.Let us see the steps −Inorder = sorted list of postorder traversal.Define a method build_tree(), this will take inorder, postorder −If inorder list is not empty −root := make a tree node with the last value of postorder, then delete that ... Read More
379 Views
Here we will see the concept of the user-defined literals in C++. From C++ version 11, the User Defined Literals (UDL) are added in C++. C++ also provides literals for a variety of built-in types but these are limited.Built-in Literals −31 (Integer)3.5 (Double)4.2F (Float)'p' (Character)31ULL (Unsigned Long Long)0xD0 (Unsigned Hexadecimal Integer)"pq" (String)Apart from the built-in literals, sometimes we need user defined literals. There are few reasons behind that. Let us see with few examples −Suppose we want to define one weight variable, but we cannot specify the units, like if we define as follows −long double Weight = 3.5;We have ... Read More
334 Views
In this section we will see when we declare a variable that is un-initialized, then which value they hold in C or C++ language.What Happens When You Don’t Initialize Variables? In C and C++, when a variable is declared inside a function (i.e., as a local variable) but not explicitly initialized, it holds an undefined or garbage value. This means the variable may contain any value that is present at that memory location.Unlike some high-level languages where variables are automatically initialized (e.g., 0 for integers, false for booleans), C and C++ do not initialize local variables by default. So, assuming ... Read More
1K+ Views
Here we will discuss about the uniform initialization in C++. This is supported from C++11 version. The uniform initialization is a feature that permits the usage of a consistent syntax to initialize variables and objects which are ranging from primitive type to aggregates. In other words, it introduces brace-initialization that applies braces ({}) to enclose initializer values.Syntaxtype var_name{argument_1, argument_2, .... argument_n}Initialize Dynamically allocated arraysExample (C++)Let us see the following implementation to get better understanding − Live Demo#include using namespace std; int main() { int* pointer = new int[5]{ 10, 20, 30, 40, 50 }; cout
2K+ Views
Here we will see the map container and its use in C++. The maps are defined as associative containers that store elements in a hash-mapped fashion. Each element is associated with a key and value. No two mapped values can have identical keys. These are some fundamental methods that are present inside the map container in C++.begin(): This returns an iterator to the first element in the map.end()− This returns an iterator to the theoretical element that follows last element in the map.size() − This returns the number of elements in the map.max_size() − This returns the maximum number of ... Read More
2K+ Views
In this section we will see the heap data structure present in C++ STL. This permits faster input into heap and retrieval of a number always results in the largest number i.e. largest number of the remaining numbers is popped out each time. Other elements of the heap are arranged which depends on the implementation. The heap operations are as follows −make_heap() − This converts a range in a container to a heap.front() − This returns first element of heap which is the largest number.ExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; int ... Read More
333 Views
In this section, we will see how to make point class using complex class from STL in C++. And apply them on some geometry related problems. The complex number is present inside the complex class from STL (#include )Defining Point ClassTo make complex to point, we will change the name of the complex as point, then change x to real() of complex class and y to imag() of complex class. Thus, we can simulate the point class.# include typedef complex point; # define x real() # define y imag()We have to keep in mind that the x and y ... Read More
318 Views
In this section we will see how we can use C++ STL function to generate test cases. Sometimes generating test cases for array programs can be very complicated and inefficient process. C++ provides two methods to generate test cases. These methods are as follows −The generate() methodThe C++ function std::algorithm::generate() assigns the value returned by successive calls to gen to the elements in the range of first to last. It takes three parameters first, last and gen, these are forward iterator to the initial position, backward iterator to the final position and generator function that is called with no argument, ... Read More