Articles tagged (
code
)




Multithreading using C++
Published 14 Jul 2021

Multithreading is useful for parallel execution of some tasks leads to a more efficient use of resources of the system. Built in support for multithreading was introduced in C++11

1f39776630d0d831472ba2d63a1921de.png9bd9b1d2e3393f3f82dc7ded6f920bb4.png

Multithreading support was introduced in C+11. Prior to C++11, we had to use POSIX threads or p threads library in C. While this library did the job the lack of any standard language provided feature-set caused serious portability issues. C++ 11 did away with all that and gave us std::thread. The thread classes and related functions are defined in the thread header file.

std::thread is the thread class that represents a single thread in C++. To start a thread we simply need to create a new thr...

155 views


Interactive Skip List
Published 01 Mar 2022

C++ implementation of a Skip List, with an interactive console

tbbvzdbvpcqnznt1rnec.png


A skip list is a probabilistic data structure. The skip list is used to store a sorted list of elements or data with a linked list. It allows the process of the elements or data to view efficiently. In one single step, it skips several elements of the entire list, which is why it is known as a skip list.


-INF <-----------------------------------------------------> 75.000000 <----> INF
-INF <-----------------------------------------------------> 75.000000 <----> INF
-INF <-------------------> 1...

95 views


Python Sorting
Published 10 Jul 2021

Sorting Methods in Python

39e3be12f579bc6277e2bff68ff7e788.png


Sorting refers to arranging data in a particular format. Sorting algorithm specifies the way to arrange data in a particular order. Most common orders are in numerical or lexicographical order.

The importance of sorting lies in the fact that data searching can be optimized to a very high level, if data is stored in a sorted manner. Sorting is also used to represent data in more readable formats. Below we see five such implementations of sorting in python.

  • Bubble Sort
  • Merge Sort
  • Insertion Sort
  • Shel...

81 views


First Article
Published 27 Jul 2021

#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>

/**
 * Estimate PI using Leibiniz series
 * 1 - (1/3) + (1/5) - (1/7) + (1/9) .... = (pi / 4)
 */

void calc(int terms) {
    long double pi = M_PI;

    long double sum = 0;
    long long int denom = 1;

    for(int i = 0; i < terms; i++) {
        sum += pow(-1, i) * ( 1 / double(denom) );
        denom += 2;
        long double estimate = sum * 4;
        long double diff = abs(pi - estimate);
        std::cout ...
67 views


CMake Tutorial
Published 09 May 2022

CMake is a cross-platform, open-source build system generator. The following tutorial is inspired by modern-cmake by Henry Schreiner

v82pxakdjj5uy13hp0qi.pngHow to Run


## Conventional Run
~/package $ mkdir build
~/package $ cd build
~/package/build $ cmake ..
~/package/build $ make

## Single Line CMake build
~/package/ $ cmake -S project -B build -G "MinGW Makefiles"
~/package/ $ make -C build
~/package/ $ build\MyExample


Once cmake build has been called, we can edit files and directly run them using


~/package/ $ make -C build && build\MyExample


Tutorial

##### ------------------- BASICS ------------------- #####

cmake_minimum_required(VERSION 3.12...
66 views