daily pastebin goal
58%
SHARE
TWEET

Untitled

Duhan Jan 18th, 2019 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <limits.h>
  5. #include <string.h>
  6.  
  7. typedef struct event_t {
  8.     int type ; // Ereignis -Typ
  9.     double time ; // Aktuelle Zeit
  10.     long serial ; // laufende Ereignisnummer , wird beim Einfuegen generiert
  11.     struct event_t * next; // Zeiger auf das nächste Element in der Liste
  12. } event_t; // = Abkürzung für struct event_t
  13.  
  14. int event_initialize() {  //Erzeugen der Ereignismenge(Liste)
  15.     event_t *head = NULL;
  16.     head = malloc(sizeof(event_t));
  17.  
  18.     head->type = 0;
  19.     head->time = 0;
  20.     head->serial = 0;
  21.     head->next = NULL;
  22.     // 0te Position (head) wurde kreirt und hat alle Variablen gleich 0
  23. }
  24.  
  25. void print_list(event_t * head) {
  26.     event_t * current = head;
  27.  
  28.     while (current != NULL) {
  29.         printf("\n Seriennummer : %ld Type: %d Time: %f\n", current->serial, current->type, current ->time);
  30.         current = current->next;
  31.     }
  32. } //gibt Variablen für jedes Ereignis aus
  33.  
  34. void event_store(event_t * head, int type, double time) {
  35.     event_t * current = head;
  36.     int serial;
  37.     while (current->next != NULL) {                    //wenn eine Vorbefüllung da ist
  38.         current = current->next;                      //eine Position weitergehen
  39. }
  40.  
  41.     /* Hinzufügen neuer Variable*/
  42.     current->next = malloc(sizeof(event_t));
  43.     current->next->type = type;
  44.     current->next->time = time;
  45.     serial ++;
  46.     current->next->serial = serial;
  47.     current->next->next = NULL;
  48. } //Kreation von Ereignissen
  49.  
  50. int event_retrieve(event_t ** head,int type, double time) {
  51.     event_t *current = *head;
  52.  
  53.     for (current = head; current != NULL; current = current->next) {
  54.         if (current->type == type && current->time == time) {
  55.             return current->serial;
  56.         }
  57.     }
  58.     printf("\n Nicht gefunden! \n");
  59.     return 0;
  60. }
  61.  
  62. int main() {                                // messen zeit bis zur ausführung
  63.     clock_t start, ende;
  64.  
  65.     start = clock();
  66.  
  67.     event_t *Duhan = event_initialize();
  68.     for(int i; i<10000; i++){
  69.         event_store(Duhan, rand(), rand());
  70.     }
  71.     ende = clock();
  72.     print_list(Duhan);
  73.     int serial = event_retrieve(Duhan, 15724, 19169);
  74.     printf("\n Mit event_t retrieve gesuchte Seriennummer = %d \n",serial);
  75.  
  76.     printf("\n Zeit fuer alles in Sekunden  = %g\n", (double) (ende - start) / CLOCKS_PER_SEC);
  77.     return 0;
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top