home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / compiler / sample03 / main03.c next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  2.7 KB  |  57 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* Sample Program 03 : MAIN03.C                                             */
  4. /*                                                                          */
  5. /* COPYRIGHT:                                                               */
  6. /* ----------                                                               */
  7. /* Copyright (C) International Business Machines Corp., 1991, 1993.         */
  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.    printf("The unsorted array is :\n");
  33.    list(unsorted, nSize);
  34.    for (i = 0; i < nSize; ++i)
  35.       sorted[i] = unsorted[i];
  36.    bubble(sorted, nSize);
  37.    printf("\nThe array sorted by bubble sort is :\n");
  38.    list(sorted, nSize);
  39.    printf("The number of swaps required was %u\n", nSwaps);
  40.    printf("The number of comparisons required was %u\n", nCompares);
  41.    for (i = 0; i < nSize; ++i)
  42.       sorted[i] = unsorted[i];
  43.    insertion(sorted, nSize);
  44.    printf("\nThe array sorted by insertion sort is :\n");
  45.    list(sorted, nSize);
  46.    printf("The number of swaps required was %u\n", nSwaps);
  47.    printf("The number of comparisons required was %u\n", nCompares);
  48.    for (i = 0; i < nSize; ++i)
  49.       sorted[i] = unsorted[i];
  50.    selection(sorted, nSize);
  51.    printf("\nThe array sorted by selection sort is :\n");
  52.    list(sorted, nSize);
  53.    printf("The number of swaps required was %u\n", nSwaps);
  54.    printf("The number of comparisons required was %u\n", nCompares);
  55.    return 0;
  56. }
  57.