home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / samples / sam03l / main03.c__ / MAIN03.C
Encoding:
C/C++ Source or Header  |  1992-04-01  |  2.8 KB  |  70 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /* Sample Program 03 : MAIN03.C                                               */
  4. /*                                                                            */
  5. /* COPYRIGHT:                                                                 */
  6. /* ----------                                                                 */
  7. /* Copyright (C) International Business Machines Corp., 1991, 1992.           */
  8. /*                                                                            */
  9. /* DISCLAIMER OF WARRANTIES:                                                  */
  10. /* -------------------------                                                  */
  11. /* The following [enclosed] code is sample code created by IBM                */
  12. /* Corporation.  This sample code is not part of any standard IBM product     */
  13. /* and is provided to you solely for the purpose of assisting you in the      */
  14. /* development of your applications.  The code is provided "AS IS",           */
  15. /* without warranty of any kind.  IBM shall not be liable for any damages     */
  16. /* arising out of your use of the sample code, even if they have been         */
  17. /* advised of the possibility of such damages.                                */
  18. /*                                                                            */
  19. /******************************************************************************/
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "sample03.h"
  24.  
  25. int main( void )
  26.    {
  27.    size_t i;
  28.    int *unsorted, *sorted;
  29.  
  30.    unsorted = pArray;
  31.    sorted = malloc( nSize * sizeof( int ) );
  32.  
  33.    srand( 17 );
  34.  
  35.    printf( "The unsorted array is :\n" );
  36.    list( unsorted, nSize );
  37.  
  38.    for ( i = 0; i < nSize; ++i )
  39.       sorted[ i ] = unsorted[ i ];
  40.  
  41.    bubble( sorted, nSize );
  42.  
  43.    printf( "\nThe array sorted by bubble sort is :\n" );
  44.    list( sorted, nSize );
  45.    printf( "The number of swaps required was %u\n", nSwaps );
  46.    printf( "The number of comparisons required was %u\n", nCompares );
  47.  
  48.    for ( i = 0; i < nSize; ++i )
  49.       sorted[ i ] = unsorted[ i ];
  50.  
  51.    insertion( sorted, nSize );
  52.  
  53.    printf( "\nThe array sorted by insertion sort is :\n" );
  54.    list( sorted, nSize );
  55.    printf( "The number of swaps required was %u\n", nSwaps );
  56.    printf( "The number of comparisons required was %u\n", nCompares );
  57.  
  58.    for ( i = 0; i < nSize; ++i )
  59.       sorted[ i ] = unsorted[ i ];
  60.  
  61.    selection( sorted, nSize );
  62.  
  63.    printf( "\nThe array sorted by selection sort is :\n" );
  64.    list( sorted, nSize );
  65.    printf( "The number of swaps required was %u\n", nSwaps );
  66.    printf( "The number of comparisons required was %u\n", nCompares );
  67.  
  68.    return 0;
  69.    }
  70.