سورس هاشو گیر اوردم با سرچ. متصل کردن و هماهنگیش رو زحمت بکشی ممنونت میشم. فقط خیلی فوریه. فدات بشم

کد:
int binarySearch(int sortedArray[], int first, int last, int key) {
   // function:
   //   Searches sortedArray[first]..sortedArray[last] for key.  
   // returns: index of the matching element if it finds key, 
   //         otherwise  -(index where it could be inserted)-1.
   // parameters:
   //   sortedArray in  array of sorted (ascending) values.
   //   first, last in  lower and upper subscript bounds
   //   key         in  value to search for.
   // returns:
   //   index of key, or -insertion_position -1 if key is not 
   //                 in the array. This value can easily be
   //                 transformed into the position to insert it.
   
   while (first <= last) {
       int mid = (first + last) / 2;  // compute mid point.
       if (key > sortedArray[mid]) 
           first = mid + 1;  // repeat search in top half.
       else if (key < sortedArray[mid]) 
           last = mid - 1; // repeat search in bottom half.
       else
           return mid;     // found it. return position /////
   }
   return -(first + 1);    // failed to find key
}
کد:
int linearSearch(int a[], int first, int last, int key) {
   // function:
   //   Searches a[first]..a[last] for key.  
   // returns: index of the matching element if it finds key, 
   //         otherwise  -1.
   // parameters:
   //   a           in  array of (possibly unsorted) values.
   //   first, last in  lower and upper subscript bounds
   //   key         in  value to search for.
   // returns:
   //   index of key, or -1 if key is not in the array.
   
   for (int i=first; i<=last; i++) {
       if (key == a[i]) {
          return i;
       }
   }
   return -1;    // failed to find key
}
کد:
Selection sort

for(int x=0; x<n; x++)

	{

		int index_of_min = x;

		for(int y=x; y<n; y++)

		{

			if(array[index_of_min]<array[y])

			{

				index_of_min = y;

			}

		}

		int temp = array[x];

		array[x] = array[index_of_min];

		array[index_of_min] = temp;

	}

کد:
Bubble sort

for(int x=0; x<n; x++)

	{

		for(int y=0; y<n-1; y++)

		{

			if(array[y]>array[y+1])

			{

				int temp = array[y+1];

				array[y+1] = array[y];

				array[y] = temp;

			}

		}

	}
کد:
 Insertion Sort Algorithm


void InsertionSort( Elem* array, int n )
{
  // Insert i'th record on the top sorted part of the array
  for (int i = 1; i < n; i++)
    for (int j = i; (j > 0) && ( array[j] < array[j-1] ); j--)
      swap( array, j, j-1 );
}