Message from C, C++ talks

July 2019

— Or just use realloc.

— 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

— While(left<=right){
mid=(left + right)/2;

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

}
cout<<result<<endl;
} No it was binary search. See.

Message permanent page

— 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 :)