In fact, the STL's map class allows you to store data by any type of key instead of simply by a numerical key, the way you must access an array or vector. So instead of having to compute a hash function and then access an array, you can just let the map class do it… Continue reading STL – Map

# Category: C++

some notes about C++

# MVC Design Pattern

MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application's concerns. Model - Model represents an object carrying data. It can also have logic to update controller if its data changes. View - View represents the visualization of the data that model contains. Controller - Controller acts on both model and view.… Continue reading MVC Design Pattern

# Sieve of Eratosthenes Algorithm

if we want to find prime numbers up to some predefined integer n, there are some steps to find the prime numbers. (trial division) find primes (int arr[]) define empty list for from i = 2 to i = n if isPrime (i) if true (add i to list) Implementation (Trial division) in c++ #include <iostream>… Continue reading Sieve of Eratosthenes Algorithm

# Singleton Pattern

<?php final class UserFactory {/** * Call this method to get singleton * * @return UserFactory */ public static function Instance() { static $inst = null; if ($inst === null) { $inst = new UserFactory(); } return $inst; } /** * Private ctor so nobody else can instance it * */ private function __construct() {… Continue reading Singleton Pattern

# Hacker Rank “Sherlock and Anagrams”

Given a string , find the number of "unordered anagrammatic pairs" of substrings. Input Format First line contains , the number of testcases. Each testcase consists of string in one line. Output Format For each testcase, print the required answer in one line. Sample Input#00 2 abba abcd Sample Output#00 4 0 Sample Input#01… Continue reading Hacker Rank “Sherlock and Anagrams”

# Stack and Queue

Stacks are a type of container designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container. Main Stack Operations: push (object): inserts an element. pop (): removes and returns the last inserted element. top(): returns the last element without removing it. size(): returns… Continue reading Stack and Queue

# Vectors

Arrays in C++ have a number of drawbacks that make them inconvenient to use: The size of the array must be a fixed constant. Passing an array as a parameter to a function is inconvenient; you must also pass the size of the array as a separate parameter. There is no way to conveniently insert… Continue reading Vectors