I am making a program that makes sum of two binary number. All is ok and all working but i need some tips how to faster algorithm.
I am thinking about changing all variables to dynamically allocated variables. Is it good idea? Make all variables dynamic, even if i use it only one or only long strings?
I need advice on how to use dynamic allocated variables.
This is example one of my checking function:
bool Correct(string v1, string v2){
for (unsigned int i = 0; i < v1.size(); ++i) {
if ((cin.fail())||((v1[i] != '1')&&(v1[i] != '0')))
return false;
}
for (unsigned int i = 0; i < v2.size(); ++i) {
if ((cin.fail())||((v2[i] != '1')&&(v2[i] != '0')))
return false;
}
return true;
}
When i use this:
bool JsouVstupySpravne(string *v1, string *v2){...}
all usages like v1.size() stop working.
cin.fail()check? You don't read anything. And if you don't modify the strings, pass them as references to constants (e.g.const string& v1).