Advertisement
Duhan

P2 Main

May 13th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <time.h>
  6. #include "queue.h"
  7.  
  8. #define MAX 10000
  9.  
  10. char * randomString (int size ) {
  11.     int i ;
  12.     char * str = ( char *) malloc (( size +1)* sizeof ( char ));
  13.     for ( i = 0 ; i < size ; ++ i ) {
  14.         str [ i ] = ( rand () % 26) + 'A';
  15.     }
  16.     str [ size ] = '\0 ';
  17.     return str ;
  18. }//vorgegeben um einen zufälligen String zu kreieren
  19.  
  20. int main() {
  21.  
  22.     int i ;
  23.     char * strings [ MAX ];
  24.     clock_t tic , toc ; //Zeit
  25.  
  26.     srand ( time ( NULL ));
  27.  
  28.     for ( i = 0 ; i < MAX ; ++ i ) {
  29.         strings [ i ] = randomString (8);
  30.     }
  31.  
  32.     priorityqueue_t * pq = pqueue_create ();
  33.  
  34.     tic = clock ();
  35.     for ( i = 0 ; i < MAX ; ++ i ) {
  36.         pqueue_insert ( pq , strings [ i ] , rand () % 100);
  37.     }
  38.     toc = clock ();
  39.     // pqueue_print(pq); //Gib die Liste aus
  40.  
  41.     printf (" insertion time : %f\n", ( float )( toc - tic ) / CLOCKS_PER_SEC );
  42.  
  43.     tic = clock ();
  44.     for ( i = 0 ; i < MAX ; ++ i ) {
  45.         pqueue_extractMinimum( pq );
  46.     }
  47.     toc = clock ();
  48.  
  49.     printf (" extract time : %f\n", ( float )( toc - tic ) / CLOCKS_PER_SEC );
  50.  
  51.     for ( i = 0 ; i < MAX ; ++ i ) {
  52.         free ( strings [ i ]);
  53.     }
  54.     pqueue_destroy ( pq );
  55.  
  56.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement