C++ · Data Structure

STL – Map

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

Advertisements
object oriented analysis and Design Pattern

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

Algorithms · C++

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

C++ · problem solving

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”

C++ · Data Structure

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