That is scholarship winning code. A+ :D
Don't forget to free your memory. :p
Printable View
Haha, thanks :D , but forgetting to free my memory is a big mistake! Bravo for your observation ;)
So right before return 0; (where main terminates at these two lines of code)
Hmm.....Code:for(i = 0 ; i < answerCounter ; i++)
free(answer[i]);
If you notice we make one pass to print and one pass to free....Thus we execute these loops at aggregate 20 times... If we had as size of array 1000 instead of 10, we would execute these two 2000 times...
So if we have as size of array answer the value n, we will do a pass of 2*n ... so do it in one pass to execute n times ;)
And because this n is how many times our while loop is going to be executed, we have to consider the above :)Code:for(i = 0 ; i < answerCounter ; i++)
{
printf("%s\n",answer[i]);
free(answer[i]);
}
Remember that the time complexity of our algorithm is determined by the heaviest operation!