10 Reusable Code Snippet Topics

Remove Filter
Member Avatar for mrnutty

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 …

Member Avatar for Tumlee
0
690
Member Avatar for mrnutty

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 ?

Member Avatar for 88omar
1
434
Member Avatar for mrnutty

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 …

Member Avatar for Rashakil Fol
0
881
Member Avatar for mrnutty

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 …

Member Avatar for griswolf
2
410
Member Avatar for mrnutty

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 …

Member Avatar for mrnutty
1
290
Member Avatar for mrnutty

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 …

Member Avatar for Dave Sinkula
2
3K
Member Avatar for mrnutty

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 …

Member Avatar for mrnutty
4
618
Member Avatar for mrnutty

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, …

0
378
Member Avatar for mrnutty
0
333
Member Avatar for mrnutty

Random number generator under its own namespace. Its a sample program.

0
301

The End.