Articles tagged (
cpp
)




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


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


Plotting an Arrow using C++
Published 23 Aug 2021

Using FLTK graphics library to draw an arrow.

ebm8tnyxdmf3lfptrnjl.png


Aim - Create a C++ program to draw an arrow:

  • between 2 given coordinates
  • arms of length as a given ratio to its body length
  • arms at specified incline to the body


kicomvydi7rataondhm2.png


Given:

  • Start point of arrow as (x1, y1) and end point (x2, y2). Eg: (2, 3) and (10, 100)
  • Ratio provided = x : y. Eg 1:10
  • Incline of arrow arms (in degrees) = θ. Eg: θ=67


Attempt 1


Attempt 1 relies on individually calculating the slope of all 3 lines and finding points of the arrow by combining equations of distance formula, tangent slope for...

66 views


STL-List-Implementation
Published 12 Jun 2023

STL List Implementation

Basic Performance Tests


$ ./a.exe 500000
std::list: 5359224 ms
list: 5368370 ms
$ ./a.exe 200000
std::list: 536497 ms
list: 487405 ms


umnro5nzdsrjtkew9bfq.png


48 views