At that post, I try to illustrate one of the use case of comparison overriding for std::sort on top of a simple problem. Our problem is as follows:
Write a method to sort an array of strings so that all the anagrams are next to each other.
At that post, I try to illustrate one of the use case of comparison overriding for std::sort on top of a simple problem. Our problem is as follows:
Write a method to sort an array of strings so that all the anagrams are next to each other.
Here we have some stupidly clever algorithms that are faster in execution but slower in convergence to solution.
First candidate to introduce you is Bogo Sort. Its idea is simpler. Shuffle the numbers until it finds the correct order. Complexity of the algorithm can be approximated as O(n.n!) (efficient hah ?). Its pseudo code can be written as;
while not isInOrder(deck):
shuffle(deck);
Next one is known as Stooge Sort. The idea is to sort the initial 2/3 part t Continue Reading
long long
is not the same as long
(although they can have the same size, e.g. in most 64-bit POSIX system). It is just guaranteed that a long long
is at least as long as a long
. In most platforms, a long long
represents a 64-bit signed integer type.
You could use long long
to store the 8-byte value safely in most conventional platforms, but it’s better to use int64_t
/int_least64_t
from <stdint.h>
/<cstdint>
to clarify that you want an integer type having ≥64-bit.