Ignore:
Timestamp:
Apr 3, 2017, 12:00:50 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, 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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/searchsort.c

    r23063ea r727cf70  
    1010// Created On       : Thu Feb  4 18:17:50 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul  5 18:06:07 2016
    13 // Update Count     : 56
     12// Last Modified On : Sun Apr  2 11:29:30 2017
     13// Update Count     : 76
    1414//
    1515
    1616#include <fstream>
    1717#include <stdlib>                                                                               // bsearch, qsort
     18#include <stdlib.h>                                                                             // C version of bsearch
     19
     20int comp( const void * t1, const void * t2 ) { return *(int *)t1 < *(int *)t2 ? -1 : *(int *)t2 < *(int *)t1 ? 1 : 0; }
    1821
    1922int main( void ) {
     
    2528                sout | iarr[i] | ", ";
    2629        } // for
    27         sout | endl;
     30        sout | endl | endl;
     31
     32        // ascending sort/search by changing < to >
    2833        qsort( iarr, size );
    2934        for ( unsigned int i = 0; i < size; i += 1 ) {
     
    3136        } // for
    3237        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;
    3344        for ( unsigned int i = 0; i < size; i += 1 ) {
    3445                int *v = bsearch( size - i, iarr, size );
    3546                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] | ", ";
    3652        } // for
    3753        sout | endl | endl;
     
    5470                        sout | *v | ", ";
    5571                } // 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
    5677        }
    5778        sout | endl | endl;
     
    7192                double *v = bsearch( size - i + 0.5, darr, size );
    7293                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] | ", ";
    7399        } // for
    74100        sout | endl | endl;
     
    93119                sout | *v | ", ";
    94120        } // 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
    95127        sout | endl | endl;
    96128} // main
Note: See TracChangeset for help on using the changeset viewer.