Originally Posted by
cfanatic
That is scholarship winning code. A+
Haha, thanks , but forgetting to free my memory is a big mistake! Bravo for your observation
Originally Posted by
cfanatic
Don't forget to free your memory.
So right before return 0; (where main terminates at these two lines of code)
Code:
for(i = 0 ; i < answerCounter ; i++)
free(answer[i]);
Hmm.....
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
Code:
for(i = 0 ; i < answerCounter ; i++)
{
printf("%s\n",answer[i]);
free(answer[i]);
}
And because this n is how many times our while loop is going to be executed, we have to consider the above
Remember that the time complexity of our algorithm is determined by the heaviest operation!