std

std::vector

Declaration

  Simple operation

  Fill with something

  Combine two vectors

  In-place solution for creating object

Originally, object gets created first in the main stack and then copied to the vector’s memory address

In-place object creation can be achieved and save the computing time for copying the object

 

Algorithms, C++

My dynamic programming journey [2] – Coin change problem

As suggested in both Quora and StackOverflow, the coin change problem should be the second problems for beginner to solve. There are actually multiple variations of this problem, however, my approach will be finishing the basic version first, which is: Given a set of coins with values, find the possible way to form N (order is not considered). Example: Given…

Continue Reading

Algorithms, C++

My dynamic programming journey [1] – Fib with memorization

It is rather complicated to consider the advance level of dynamic programming at the beginning, so I have decided to start with a basic example: finding Fibonacci numbers. Since the concepts of recursion and memorization are often required in dynamic programming, therefore, I have implemented a version of memorization. Set base case of 0 and 1 equal to 1 Check…

Continue Reading

Algorithms, C++

Breadth first search

Steps: Add root to queue If left child not null, add it to queue If right child not null, add it to queue Repeat 2 & 3 until the queue is empty

 

C, C++, Language

CMake command

Set variable Basic usage of SET

  To include existing variables in the SET

  To include multiple items in SET

  Include include path (header)   Suppose we have the header files like this

  To globally add the include path, use include_directories

  To specially add the include path for target, use target_include_directories

Continue Reading

C++

Google C++ style guide

Filenames should be all lowercase with underscores (_) or dashes (-) hello_world.cc   All types like classes, structs, type aliases, enums, and type should be capitalized. class Person   Variables should be all lowercase with underscores string table_name   Data member in the class (not struct) should contain a trailing underscores string var_in_class_   Use a struct only for passive objects that carry…

Continue Reading

C++

C++ 11

Auto type

  Auto type + Ranged-based for loop

  Initializer list

  Strongly-typed enum

  Compile time assert

 

C++

fscanf problems with double

Trying to get input from the FILE* stream with image processing filter.   Example One:   Sample input (.txt)

Code snippet for scanning the double

Setting breakpoint in visual studio 2017, the filter.m returns set of values as the following

Which the first value, 0.7, wrongly being scanned as 0.69999999999999996.   Example Two:   Sample input (.txt)

Continue Reading

Algorithms, C++, std

std::map

Simple insert

  Access to second element using key (C++ 11)

  Iterate

  Find element

 

std

std::set

Simple insert

  Quick match

  Store search result

  Check if duplicate insert