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
C++ Articles - Page 391 of 719
214 Views
Suppose we have two sorted arrays A1 and A2, and another value k. We have to define a pair (u, v) which is consists of one element from A1 and another element from A2. We have to find the k pairs like [(u1, v1), (u2, v2), …, (uk, vk)]. So if A1 = [1, 7, 11] and A2 = [2, 4, 6], and k = 3, then output will be [(1, 2), (1, 4), (1, 6)]To solve this, we will follow these steps −Define one data type, that will take two values a and b, and index.create one priority queue, ... Read More
155 Views
Suppose we have a binary tree, where each node has following fields: (data, left, right, next), the left will point to left subtree, right will point to right subtree, and the next pointer will point to the next node. If there is no node in the right hand side, then that will be null. So initially each next pointer is set to null, we have to make the links. Suppose the tree is like the first one, it will be converted to the next node −To solve this, we will follow these steps −set pre := root, nextPre := null ... Read More
284 Views
Suppose we have a complete binary tree, where each node has following fields: (data, left, right, next), the left will point to left subtree, right will point to right subtree, and the next pointer will point to the next node. If there is no node in the right hand side, then that will be null. So initially each next pointer is set to null, we have to make the links. Suppose the tree is like the first one, it will be converted to the next node −To solve this, we will follow these steps −set pre := root, nextPre := ... Read More
302 Views
Suppose we have a linked list, we have to perform the insertion sort on this list. So if the list is like [9, 45, 23, 71, 80, 55], sorted list is [9, 23, 45, 55, 71, 80].To solve this, we will follow these steps −dummy := new Node with some random valuenode := given listwhile node is not null, newNode = next of node, dummyHead := next of dummy, prevDummyHead := dummywhile true −if dummyHead is not present, value of dummyHead > value of nodenext of node := dummyHeadnext of prevDummyHead := nodebreak the loopprevDummyHead := dymmyHead, and dummyHead = ... Read More
372 Views
Suppose we have a triangle. We have to find the minimum path sum from top to the bottom. In each step, we can move to adjacent numbers on the row below.For example, if the following triangle is like[ [2], [3, 4], [6, 5, 7], [4, 1, 8, 3] ]The minimum path sum from top to bottom is 11 (2 + 3 + 5 + 1 = 11).Let us see the steps −Create one table to use in Dynamic programming approach.n := size of trianglefor i := n – 2 down to 0for ... Read More
167 Views
List are the type of containers that stores data in sequential manner and allocate noncontiguous memory to the elements. In C++, lists are considered as doubly linked list where insertion and deletion of elements can be done from both the ends and therefore, it is also possible to traverse the list from both the end. For using singly linked list we use the forward list available in C++ STL.Advantage of using List over vector is thatList are faster in insertion and deletion of elements available in list container if the iterator is positioned to the correct element.Disadvantage of using List ... Read More
461 Views
In C++ STL, stack is used as container which is implemented as LIFO structure. LIFO means Last In First Out. Stack can view as a pile of books in which the books are arranged one above the another and the last inserted book will be the first one to be removed that’s why it is called as a LIFO structure.The operations associated with the stack are -Top() - This function returns the reference to the topmost element of a stack.Syntax - name_of_stack.top()Parameters - No ParameterReturn Value - Reference to the topmost element of a stack containerPush() - This function is ... Read More
259 Views
Functions are like a machine as they perform some functionality and produces a result of some type. Like, machine takes some input, process that input and produce an output similarly, function takes some value, operates on those value and produces the output. Manually a person passes the input to the machine then only the machine will start its functionality in the same manner when the programmer calls the function it will start executing.Functions can be different in name in various languages, but they share two common characteristics like −They contain sequence of instructions that needs to be processedThose instructions are ... Read More
633 Views
In this article, we will be discussing the raw string literal in C++, its meaning, and examples.There are escape characters in C++ like “” or “\t”. When we try to print the escape characters, it will not display on the output. To show the escape characters on the output screen we use a raw string literal by using R”(String with escape characters)”. After using R in the front of the string the escape character will be displayed on the output.ExampleLet’s understand this with the help of an example Live Demo#include using namespace std; int main(){ string str = "tutorialspoint" ... Read More
4K+ Views
In this article, we will be discussing the working, syntax, and examples of modulus functions in C++.What is modulus function C++?modulus function object class in C++, which is defined in header file. modulus function is a binary function object class used to get the result of the modulus operation of the two arguments. This function works the same as the operator ‘% ‘.Syntax of modulus functionTemplate struct modulus : binary_function { T operator() (const T& a, const T& b) const {return a%b; } };Template parametersThe function accepts the following parameter(s) −T − This is the type of the ... Read More