Message from C, C++ talks

July 2019

— This. And I would suggest to call reserve as far as it's future size is known.

— I don't know that... Thats cool

— Is it like flag?

— Also, I think there's something with the algorithm itself, because if it's the binary search then why you have the second for loop. It feels like you're doing it linearly. But it looks even stranger

Message permanent page


mid=(left + right)/2;

if(array[mid]==query) {
else if(array[mid]>query) right=mid-1;
else left=mid+1;

} No it was binary search. See.

— This allocates chunk of memory that can hold the asked amount of elements.
So when you do push_back it doesn't call for additional reallocations

Message permanent page

— Yeag

— I know how storing stuff In memory works

— Its pretty clever to have such function

— But why there's a loop around it?

— Ok, seems I got it. It searches for m elements right?

— However it requires some experience with the allocated storage duration and is used in C. Using vectors would be much simpler way.

Message permanent page

— Did you go through the first link. In this problem it is searching the element inside the array m number of times. We have to search m numbers inside the array, if they exist we will print the index and if it doesn't it will print -1.

Message permanent page

— I'm not very good at reading tasks, sorry :)

— Its okay. You don't need to be sorry for anything.I guess that's why we are here to learn and adopt new good habits.

Message permanent page