Server Side Programming Articles

Page 1471 of 2109

C++ Program to Perform Searching Based on Locality of Reference

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 212 Views

Searching based on locality of reference, depends upon the memory access pattern data elements are reallocated.Here linear searching method is used to search an element.AlgorithmBegin    int find(int *intarray, int n, int item)    intialize comparisons = 0    for i = 0 to n-1       Increase comparisons    if(item == intarray[i])       Print element with its index    break    if(i == n-1)       Print element not found    return -1    Print Total comparisons    For j = i till i>0       intarray[j] = intarray[j-1]       intarray[0] = ...

Read More

Pointers, smart pointers and shared pointers in C++

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 6K+ Views

PointersPointers are used to store the address of variable.SyntaxType *pointer;InitializationType *pointer; Pointer = variable name;Functionspointers are used to store address of variable.pointers can have a null value assigned.pointer can be referenced by pass by reference.a pointer has its own memory address and size on the stack.Example#include using namespace std; int main() {    // A normal integer variable    int a = 7;    // A pointer variable that holds address of a.    int *p = &a;    // Value stored is value of variable "a"    cout

Read More

C++ Program to Find the maximum subarray sum using Binary Search approach

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 409 Views

Binary search is a fast search algorithm with run-time complexity of Ο(log n). This search algorithm works on the principle of divide and conquer. For this algorithm to work properly, the data collection should be in the sorted form.Binary search looks for a particular item by comparing the middle most item of the collection. If a match occurs, then the index of item is returned. If the middle item is greater than the item, then the item is searched in the sub-array to the left of the middle item. Otherwise, the item is searched for in the sub-array to the ...

Read More

C++ Program to Find Closest Pair of Points in an Array

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 932 Views

This is the program to find closest pair of points in an array.AlgorithmsFor Distance between Closest pointBegin    Declare function Closest_dist_Spoint(poi stp[], int s, double dist, poi &pnt1, poi &pnt2) to the double datatype.    Declare Minimum to the double datatype.       Initialize Minimum = dist.    for (int i = 0; i < s; ++i)       for (int j = i+1; j < s && (stp[j].poi2 - stp[i].poi2) < Minimum; ++j)          if (Distance(stp[i], stp[j]) < Minimum) then          Minimum = Distance(stp[i], stp[j]).             ...

Read More

Print prime numbers in a given range using C++ STL

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 701 Views

It is the program to print prime numbers in a given range.AlgorithmsBegin    Declare a user define datatype stl.    Declare a vector number to the stl datatype.    Declare variable a to the stl datatype.    Declare vector Prime_Number to the Boolean datatype.       Prime_Number[0] = false.       Prime_Number[1] = false.    Declare b to the integer datatype.       Initialize b = sqrt(a).    for (stl pr=2; pr

Read More

C++ Program to Create the Prufer Code for a Tree

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 875 Views

Prufer code uniquely identifies a tree which is given by user as a graph representation with labels from 1 to p. This tree consist p(value is given by user) labels of node. It has sequence of p – 2 values.AlgorithmBegin    Declare i, j, ver, edg, minimum, p to the integer datatype.    Print “Enter the number of vertexes: ”.    Enter the value of ver.    Initialize edg = ver-1.    Declare EDG[edg][2], DG[ver+1] to the integer datatype.       Initialize DG[ver+1] = {0}.    Print “This tree has (value of edg) edges for (value of ver) vertexes”. ...

Read More

memset in C++

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 1K+ Views

In this section we will see what is the purpose of memset() function in C++. This function converts the value of a character to unsigned character and copies it into each of first n character of the object pointed by the given str[]. If the n is larger than string size, it will be undefined.The syntax of the memset() functionvoid* memset( void* str, int c, size_t n);In this example will use one string, then convert each character to some other character up to length n.Example#include using namespace std; int main() {    char str[] = "Hello World";    memset(str, 'o', ...

Read More

Getting a subvector from a vector in C++

Samual Sam
Samual Sam
Updated on 11-Mar-2026 6K+ Views

This is a C++ program for getting a subvector from a vector in C++AlgorithmBegin   Declare s as vector s(vector const &v, int m, int n) to    initialize start and end position of vector to constructor.       auto first = v.begin() + m.         auto last = v.begin() + n + 1.       Declare a variable vector of vector type.          Pass the value of first and last position of vector.       Return vector.    Declare a template T.    Declare a function show().       ...

Read More

How to shuffle a std::vector in C++

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

A vector shuffle can be done in the Fisher-Yates shuffle algorithm.In this algorithm, a linear scan of a vector is done and then swap each element with a random element among all the remaining element, including the element itself.AlgorithmBegin   Declare a function show().       Pass a constructor of a vector as a parameter within show() function.       for (auto const& i: input)          Print the value of variable i.       Declare v of vector type.          Initialize some values into v vector in array pattern.     ...

Read More

match max_size() function in C++ STL

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 156 Views

The match max_size() function in C++ STL returns the maximum number of elements in the match_results object that can be held by the match container.This function does not accept a parameter.Example Code#include #include using namespace std; int main() {    match_results m;    cout

Read More
Showing 14701–14710 of 21,090 articles
Advertisements