الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

أمر مستعجل جزاكم الله خير

مغلق
بدأه linearsearch في 21 أكتوبر 2003 · 2 رد · 995 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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);

#2

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.

#3

السلام عليكم

اليك كود 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;
}

بالنسبة للذى كتبته ياخ علاء الدين هذا كود عمل شجره البحث الثنائى و هو مختلف تماما عما نريده .....

واتمنى ان اكون قد ساعدتك فيما تريد ...

وان احتجت الى أى شيئ انا فى الخدمة ....

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر ساعة · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…