Optimization code for a debug function (c++11 with templates) [closed]

std::forward_list::max_size returns the maximum number of elements that the forward_list container can hold. Your forward list implementation should be: //Forward list template<> struct F22<true>{ template<typename T> static void F23(const string& name, const T& a){ std::size_t i = 0; for (const auto& e : a) { std::cout << name << “[” << i << “]: ” … Read more

Modulus of a very large number

BigInteger has the divideAndRemainder(…) method, one that returns a BigInteger array, the first item the division result, and the second, the remainder (which is what mod really does in Java). Update Including comment by Mark Dickinson to other answer: There’s a much simpler linear-time algorithm: set acc to 0, then for each digit d in … Read more

my first c++ program runtime is super long like 5 – 10 minutes on a fast CPU it's a very basic c++ program [closed]

This seems like it was purposefully un-optimized. I would assume that the time constraints are coming from modding a variable 100,000,000,000 times. But wait, that is not all. Not only do you mod a variable that many times, but when a variable modded to 0, you iterate another 11 times over each char in “Hello … Read more