Here is a piece of C++ code that seems very peculiar. For some strange reason, sorting the data miraculously makes the code almost six times faster.
Continue ReadingC++: Heap Sort
#include <algorithm> // for std::make_heap, std::sort_heap template <typename Iterator> void heap_sort(Iterator begin, Iterator en
Continue ReadingC++: Insertion Sort
#include <algorithm> template<class Iterator> void insertion_sort( Iterator a, Iterator end ) { std::iter_swap( a, std::min_ele
Continue ReadingJava += operator
Until today I thought that for example: i += j; is just a shortcut for: i = i + j; But what if we try this: int i = 5; long j = 8; Then i = i +
Continue ReadingBest C++ Books
Reference Style - All Levels A Tour of C++ (Bjarne Stroustrup) The "tour" is a quick (about 180 pages and 14 chapters) tutorial overview of all
Continue ReadingC++: Levenshtein Distance
template <class T> unsigned int edit_distance(const T& s1, const T& s2) { const size_t len1 = s1.size(), len2 = s2.size(); vect
Continue ReadingC++: Binary Search
//! \brief A recursive binary search using STL vectors //! \param vec The vector whose elements are to be searched //! \param start The index of
Continue ReadingC++: Longest Common Substring
#include <string> using std::string; int LongestCommonSubstring(const string& str1, const string& str2) { if(str1.empty() |
Continue ReadingWhat is “:-!!” in C code?
I bumped into this strange macro code in /usr/include/linux/kernel.h: /* Force a compilation error if condition is true, but also produce a resul
Continue ReadingC++: What is the name of the “–>” operator?
After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that it compiled and worked in both V
Continue Reading




