10 Reusable Code Snippet Topics
Remove Filter This code below add two positive numbers in any base from binary to base 36 with any length allowed by memory. The snippet comes with examples. There might be some bugs, because I haven't tested extensively, so forgive me if you find bugs. Hope people find it useful somehow. Thanks … | |
The simplest sort, although inefficient. Below is a demonstration of bubble sort and insertion sort. The bubble sort just consists of 2 for loops and std::swap. The insertion sort uses 2 loops as well but not as much swap as bubble sort. Any questions ? | |
Its a typical implementation of mergesort algorithm. It runs in a stable time of O(n*log(n) ). Just thought, I would add it to the library. Its been tested, although not very throughly, so if any bugs are found, just post it here, so others can be aware of them. Its … | |
This is a simple demonstration of meta programming. It shows the idea of meta programming. It basically calculates the factorial of a number before runtime. When I first saw the concept of meta programming, it blew my mind so badly. I was so surprised that one could do this. Its … | |
We are all tired of from our daily lives. So I suggest to sit back and play this game. I present here a hangman game( text version ) for your enjoyment. There might be some bugs as I haven't throughly tested it, so sorry if you find it( I'm sure … | |
Some background. We all used the string class, but some of you might not know that string is just a typedef of basic_string. In fact here is the typedef you might find when looking in the XString library. [code] typedef basic_string<char, char_traits<char>, allocator<char> > string; [/code] This code snippet shows … | |
The function adds two large numeric string together, like "12345667" + "12345678" = ? It does not have complete error checking, I'll leave that up to you. It should work but I am prone to bugs, so do advise if bugs are found. Included are also helper function that helps … | |
It uses the idea of Seive of Eratosthenes. The code is basically does the following to find Prime Numbers : 1) Populate Array from 0 - > MAX 2) Find 1st Prime, which is 2 3) Delete all Multiple of 2, i.e set it to false 4) Find next prime, … | |
Convert string to other datatypes via template. See below. | |
Random number generator under its own namespace. Its a sample program. |
The End.