function [ Ind] = exponSearch(arr, n, x)
if arr(0) == x
currentIndex = 0;
end
i=1;
while i<n && arr(i) <= x
i= i.*2;
Ind = binSearch(V, i/2, min(i,n), x);
end
function Cind = binarySearch(V, l, r, x)
if r >= l
mid = ceil(l+(r-l)/2);
if V(mid) == x
end
%if the target is smaller than the middle element
if V(mid) >x
Cind= binSearch(V, l, mid-1,x);
disp(Cind);
end
Cind = binSearch(V,mid+1,r,x);
end
end
end

 채택된 답변

John D'Errico
John D'Errico 2017년 5월 3일

0 개 추천

It does exactly what it does. There is no problem that we can see, since we have no idea what it is supposed to do. Is the goal to return an error message, probably that no function or variable named binSearch exists?
When you have a problem with code, tell us what the error that is returned. Otherwise, we need to guess.
I might point out that there is NO binSearch function provided. Nothing with that name, yet you call it repeatedly. Interestingly, there is a function named binarySearch. Perhaps you were just being lazy. But it would seem this is an obvious flaw, unless of course, you have some code named binSearch somewhere on your search path.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

질문:

2017년 5월 3일

답변:

2017년 5월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by