Changeset 727cf70f for src/tests/searchsort.c
- Timestamp:
- Apr 3, 2017, 12:00:50 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- a6af031
- Parents:
- 23063ea (diff), 1d29d46 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/searchsort.c
r23063ea r727cf70f 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 5 18:06:07 201613 // Update Count : 5612 // Last Modified On : Sun Apr 2 11:29:30 2017 13 // Update Count : 76 14 14 // 15 15 16 16 #include <fstream> 17 17 #include <stdlib> // bsearch, qsort 18 #include <stdlib.h> // C version of bsearch 19 20 int comp( const void * t1, const void * t2 ) { return *(int *)t1 < *(int *)t2 ? -1 : *(int *)t2 < *(int *)t1 ? 1 : 0; } 18 21 19 22 int main( void ) { … … 25 28 sout | iarr[i] | ", "; 26 29 } // for 27 sout | endl; 30 sout | endl | endl; 31 32 // ascending sort/search by changing < to > 28 33 qsort( iarr, size ); 29 34 for ( unsigned int i = 0; i < size; i += 1 ) { … … 31 36 } // for 32 37 sout | endl; 38 for ( unsigned int i = 0; i < size; i += 1 ) { // C version 39 int key = size - i; 40 int *v = bsearch( &key, iarr, size, sizeof( iarr[0] ), comp ); 41 sout | *v | ", "; 42 } // for 43 sout | endl; 33 44 for ( unsigned int i = 0; i < size; i += 1 ) { 34 45 int *v = bsearch( size - i, iarr, size ); 35 46 sout | *v | ", "; 47 } // for 48 sout | endl; 49 for ( unsigned int i = 0; i < size; i += 1 ) { 50 unsigned int posn = bsearch( size - i, iarr, size ); 51 sout | iarr[posn] | ", "; 36 52 } // for 37 53 sout | endl | endl; … … 54 70 sout | *v | ", "; 55 71 } // for 72 sout | endl; 73 for ( unsigned int i = 0; i < size; i += 1 ) { 74 unsigned int posn = bsearch( size - i, iarr, size ); 75 sout | iarr[posn] | ", "; 76 } // for 56 77 } 57 78 sout | endl | endl; … … 71 92 double *v = bsearch( size - i + 0.5, darr, size ); 72 93 sout | *v | ", "; 94 } // for 95 sout | endl; 96 for ( unsigned int i = 0; i < size; i += 1 ) { 97 unsigned int posn = bsearch( size - i + 0.5, darr, size ); 98 sout | darr[posn] | ", "; 73 99 } // for 74 100 sout | endl | endl; … … 93 119 sout | *v | ", "; 94 120 } // for 121 sout | endl; 122 for ( unsigned int i = 0; i < size; i += 1 ) { 123 S temp = { size - i, size - i + 1 }; 124 unsigned int posn = bsearch( temp, sarr, size ); 125 sout | sarr[posn] | ", "; 126 } // for 95 127 sout | endl | endl; 96 128 } // main
Note: See TracChangeset
for help on using the changeset viewer.