Write a recursive function RecursiveBinarySearch that search for a given key in a single subscripted sorted array of integers. Use pointer to manipulate the array elements. The prototype of the function is int RecursiveBinarySearch(int *, int, int, int);
أمر مستعجل جزاكم الله خير
مغلق
hint:
the BST is a sorted tree,so :
if the( key<the head or the 1st subscript) search in the left part,using recursive
ie: call the function and pass to it the key and the left part.
else
if (key >head) search the right part
else
(key= head)
#note: in case you are working with arrays instead of BST,replace left and right by
low and high.
السلام عليكم
اليك كود Recursive Binary Search
int RecursiveBinarySearch(int* arr,int key,int lo ,int hi)
{
int mid = (lo + hi) / 2;
if(lo<=hi)
if (key==arr[mid])
return mid;
if (key<arr[mid])
return BinarySearch(arr,key,lo,mid - 1);
else
return BinarySearch(arr,key,mid+1,hi);
return -1;
}بالنسبة للذى كتبته ياخ علاء الدين هذا كود عمل شجره البحث الثنائى و هو مختلف تماما عما نريده .....
واتمنى ان اكون قد ساعدتك فيما تريد ...
وان احتجت الى أى شيئ انا فى الخدمة ....
هذا الموضوع مغلق.