Public paste
Undefined
By: Guest | Date: Mar 7 2010 13:32 | Format: None | Expires: never | Size: 622 B | Hits: 1127

  1. ELEMENT ( A, n, x )
  2.         left := 0
  3.         right := n - 1
  4.         while left <= right do
  5.                 begin
  6.                         pivot := ( left + right ) div 2;
  7.                         if ( A [ pivot ] > x ) then
  8.                                 right := pivot - 1
  9.                         else if ( A [ pivot ] < x ) then
  10.                                 left := pivot + 1
  11.                         else
  12.                                 return pivot;
  13.                 end;
  14.         return - 1;
  15.  
  16. //a jak ktos woli w C..
  17. int element ( int * iData, int iLeft, int iRight, int x ) {
  18.         int iPivot;
  19.         while ( iLeft <= iRight ) {
  20.                 iPivot = ( iLeft + iRight ) >> 1;
  21.                 if ( iData [ iPivot ] > x ) { iRight = iPivot - 1; continue; }
  22.                 if ( iData [ iPivot ] < x ) { iLeft = iPivot + 1; continue; }
  23.                 return iPivot; }
  24.         return - 1; }