Skip to main content
11 events
when toggle format what by license comment
Mar 30, 2017 at 9:34 comment added Android1 Thanks for your help. That helped.
Mar 30, 2017 at 2:10 vote accept Android1
Mar 29, 2017 at 14:19 comment added Blauelf int min = 0; int max = n - 1; provide initialisation together with the declaration. Those are initial values, you'll change them inside the loop. Keep in mind that min, max, and mid are indices, and never values.
Mar 29, 2017 at 13:37 comment added Android1 I don't understand what to do. I'm new to all this. Can't I define the mid-point like this : int mid = (max + min) / 2; ? Also how can I define Max and Min as variables here when they change?
Mar 29, 2017 at 13:31 comment added Blauelf "initialisation" is the first assignment after declaring a variable. If it's not a global variable, the value is undefined until that point, and you should not use its value anywhere. min and max should be indices, not values. After initialisation of min and max, there should be one loop (like the while(max>=min) you suggested), and inside, after calculation of mid, some if-else or if-elseif-else structure, no other loops.
Mar 29, 2017 at 13:25 vote accept Android1
Mar 30, 2017 at 2:10
Mar 29, 2017 at 13:25 vote accept Android1
Mar 29, 2017 at 13:25
Mar 29, 2017 at 13:25 vote accept Android1
Mar 29, 2017 at 13:25
Mar 29, 2017 at 13:25 comment added Android1 Should the extra loop be ' while(max>=min) ' as an outside loop or something like that?
Mar 29, 2017 at 13:13 comment added Android1 I changed those variables to this: int min; int max; int mid = (max + min) / 2; It's now throwing the errors that max and min haven't been initialized when they were used in the last part (int mid = (max + min) / 2;). I thought that they were initialized in the 2 lines above that.
Mar 29, 2017 at 12:17 history answered Blauelf CC BY-SA 3.0