Advertisement
Guest User

MAIN SORTIROVKI

a guest
Jan 22nd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define MAX 1500
  5. #include "SORTW.H"
  6.  
  7.  
  8. void main(void)
  9. {
  10.     static float a[MAX];
  11.     int si, fi, N_CMP, N_MOVE;
  12.     long t;
  13.  
  14.     void (*Fill[])(float* mas, int n) =
  15.     {
  16.       FillDecr, FillIncr, FillRand /*, FillEqual, FillMostly*/
  17.     };
  18.  
  19.     void (*Sort[])(float* mas, int n, int* n_cmp, int* n_move) =
  20.     {
  21.       QuickSort,/* MergeSort,*/ SelectionSort, InsertionSort, BSort1,/* BSort2,*/ BSort3/*, HeapSort*/
  22.     };
  23.  
  24.     char* SortNames[] =
  25.     {
  26.       "QuickSort", /*"MergeSort",*/ "SelectionSort", "InsertionSort", "       BSort1",/* "       BSort2",*/ "       BSort3"/*, "HeapSort"*/
  27.     };
  28.  
  29.     for (si = 0; si < sizeof(Sort) / sizeof(Sort[0]); si++)
  30.     {
  31.         printf("%13s: ", SortNames[si]);
  32.         for (fi = 0; fi < sizeof(Fill) / sizeof(Fill[0]); fi++)
  33.         {
  34.             N_CMP = 0;
  35.             N_MOVE = 0;
  36.             t = clock();
  37.             Fill[fi](a, MAX);
  38.             Sort[si](a, MAX, &N_CMP, &N_MOVE);
  39.             t = clock() - t;
  40.             if (CheckSort(a, MAX))
  41.             {
  42.                 printf("%7.2f ", t / (double)CLOCKS_PER_SEC);
  43.                 printf("%10i ", N_MOVE);
  44.                 printf("%10i ", N_CMP);
  45.             }
  46.             else
  47.                 printf("     no    ");
  48.         }
  49.         printf("\n");
  50.     }
  51.     printf("\n");
  52.     printf("Sortproject");
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement