- ELEMENT ( A, n, x )
- left := 0
- right := n - 1
- while left <= right do
- begin
- pivot := ( left + right ) div 2;
- if ( A [ pivot ] > x ) then
- right := pivot - 1
- else if ( A [ pivot ] < x ) then
- left := pivot + 1
- else
- return pivot;
- end;
- return - 1;
- //a jak ktos woli w C..
- int element ( int * iData, int iLeft, int iRight, int x ) {
- int iPivot;
- while ( iLeft <= iRight ) {
- iPivot = ( iLeft + iRight ) >> 1;
- if ( iData [ iPivot ] > x ) { iRight = iPivot - 1; continue; }
- if ( iData [ iPivot ] < x ) { iLeft = iPivot + 1; continue; }
- return iPivot; }
- return - 1; }
Undefined
By: Guest | Date: Mar 7 2010 13:32 | Format: None | Expires: never | Size: 622 B | Hits: 1226
Latest pastes
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago