Programming Articles - Page 2475 of 3366

"static const" vs "#define" vs "enum" ?

sudhir sharma
Updated on 20-Aug-2019 08:22:23

5K+ Views

"static const"“static const” is basically a combination of static(a storage specifier) and const(a type qualifier).The static determines the lifetime and visibility/accessibility of the variable. This means if a variable is declared as a static variable, it will remain in the memory the whole time when the program is running, while the normal or auto variables are destroyed when the function (where the variable was defined) is over.The const is a type qualifier. A type qualifier is used to express additional info about a value through type system. When a variable is initialized using the const type qualifier, it will not ... Read More

"delete this" in C++?

sudhir sharma
Updated on 20-Aug-2019 08:19:16

2K+ Views

Delete is an operator that is used to Deallocate storage space of Variable.This pointer is a kind of pointer that can be accessed but only inside nonstatic member function and it points to the address of the object which has called the member function.This pointer holds the address of the current object, in simple words, you can say that this pointer points to the current object of the classWhenever we call a member function through its object, compiler secretly passes the address of calling that object as the first parameter in member function as this pointer.Generally, delete operator should not ... Read More

C/C++ Tokens?

sudhir sharma
Updated on 20-Aug-2019 08:13:18

9K+ Views

C++ Tokens are the smallest individual units of a program.C++ is the superset of C and so most constructs of C are legal in C++ with their meaning and usage unchanged. So tokens, expressions, and data types are similar to that of C.Following are the C++ tokens : (most of c++ tokens are basically similar to the C tokens)KeywordsIdentifiersConstantsVariablesOperatorsKeywordsKeywords are reserved words which have fixed meaning, and its meaning cannot be changed. The meaning and working of these keywords are already known to the compiler. C++ has more numbers of keyword than C, and those extra ones have special working ... Read More

Add n binary strings?

sudhir sharma
Updated on 20-Aug-2019 08:08:41

408 Views

In this program we have to add binary numbers given. there are n binary numbers and we have to add them all to give one binary number as an output.For this we will use binary addition logic and add all the terms from 1 to N one by one to gain the result.Input: "1011", "10", "1001" Output: 10110ExplanationThe easier method is by converting binary string to its decimal equivalent, then add them and convert into binary again. Here we will do the addition manually. We will use one helper function to add two binary strings. That function will be used ... Read More

Binary Search Tree insert with Parent Pointer in C++

Arnab Chakraborty
Updated on 20-Aug-2019 07:53:29

841 Views

We can insert new node into the BST in recursive manner. In that case we return the address of the root of each subtree. Here we will see another approach, where parent pointer will need to be maintained. Parent pointer will be helpful to find ancestor of a node etc.The idea is to store the address of the left and right subtrees, we set parent pointers of the returned pointers after recursive call. This confirms that all parent pointers are set during insertion. The parent of root is set to null.Algorithminsert(node, key) −begin    if node is null, then create ... Read More

Binary Search (bisect) in Python

Arnab Chakraborty
Updated on 02-Jul-2020 06:15:22

2K+ Views

Here we will see the bisect in Python. The bisect is used for binary search. The binary search technique is used to find elements in sorted list. The bisect is one library function.We will see three different task using bisect in Python.Finding first occurrence of an elementThe bisect.bisect_left(a, x, lo = 0, hi = len(a)) this function is used to return the left most insertion point of x in a sorted list. Last two parameters are optional in this case. These two are used to search in sublist.Examplefrom bisect import bisect_left def BinSearch(a, x):    i = bisect_left(a, x)   ... Read More

Array Manipulation and Sum using C/C++

Farhan Muhamed
Updated on 21-Jul-2025 19:00:29

3K+ Views

In this problem, you are given an integer array arr of size n and an integer S. Your task is to find an element k in the array such that if all the elements greater than k in the array are replaced with k, then the sum of all the elements of the resultant array becomes equal to S. If such an element exists, print it; otherwise, print -1. Scenario 1: Input: int S = 9; int arr[] = { 1, 3, 2, 5, 8 }; Output: ... Read More

Array Index with same count of even or odd numbers on both sides in C++

Arnab Chakraborty
Updated on 20-Aug-2019 07:43:06

168 Views

Here we will see one problem, suppose one array is given. There are n elements. We have to find one index, where frequency of even numbers of its left and the frequency of even numbers of its right side are same, or the frequency of odd numbers of its left is same as the frequency of odd numbers of its right. If no such result is there, return -1.Suppose the array is like {4, 3, 2, 1, 2, 4}. The output is 2. The element at index 2 is 2, there is only one odd number at left of it, ... Read More

Array algorithms in C++ STL

Ravi Ranjan
Updated on 24-Jul-2025 18:35:20

725 Views

The C++ STL or Standard Template Library is a collection of general-purpose classes and functions with templates for implementing many algorithms and data structures such as vectors, lists, queues, and stacks. The 4 components of STL are: Containers, Algorithms, Iterators, and Functors. In this article, we will discuss the functions of the header that work on arrays, and are introduced in C++ 11 and later versions. C++ Header The algorithm header provides various built-in functions that implement algorithms such as searching, sorting, finding the maximum element, etc. These functions perform various operations on containers such ... Read More

Area of the Largest Triangle inscribed in a Hexagon in C++

Ravi Ranjan
Updated on 28-Jul-2025 17:57:50

405 Views

In this problem, our task is to find the area of the largest triangle that can be inscribed in a regular hexagon. Each side of the hexagon and triangle is of length a and b, respectively. Area of the Largest Triangle Inscribed in a Hexagon You can calculate the area of the largest triangle inscribed in a regular hexagon using the following formula: $$ Area\ of\ triangle\ inside\ hexagon\ = \frac{3\sqrt{3}}{4} \cdot a^2 $$ Derivation The first step is to establish a relation between a and b, as the value of a(side of the hexagon) is ... Read More

Advertisements