- Timestamp:
- Apr 2, 2017, 12:20:37 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:
- 0788c03d, ee89ad43
- Parents:
- 06cf47f
- Location:
- src/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/.expect/searchsort.txt
r06cf47f rf2cdc44 1 1 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2 2 3 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 3 5 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 4 6 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -
src/tests/searchsort.c
r06cf47f rf2cdc44 10 10 // Created On : Thu Feb 4 18:17:50 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Apr 1 19:10:12201713 // Update Count : 6212 // 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 ) { 30 35 sout | iarr[i] | ", "; 36 } // for 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 | ", "; 31 42 } // for 32 43 sout | endl;
Note: See TracChangeset
for help on using the changeset viewer.