Ternary search in C

前端 未结 4 905

I want to do a ternary search for integers in C ... I have tried it...but it\'s not working well for particular cases. Please help me to remove the bugs from the following progr

4条回答
  •  情歌与酒
    2021-01-24 03:38

    The midpoint calculations are wrong. The way you have it, m1 and m2 are not between i and j.

    try

     m1 = i + (j - i) * 1 / 3;
     m2 = i + (j - i) * 2 / 3;
    

提交回复
热议问题