SHARE
TWEET

Untitled

a guest Aug 13th, 2017 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void push(priority_queue* queue, value_type value, uint remaining_time) {
  2.     priority_queue_item *item;
  3.     item = malloc(sizeof(priority_queue_item));
  4.     item->value = value;
  5.     item->remaining_time = remaining_time;
  6.     item->next = NULL;
  7.     item->previous = NULL;
  8.  
  9.     if (queue->size != 0) {
  10.         if(item->remaining_time <= queue->first->remaining_time) { // radime na zacatek fronty
  11.             item->previous = queue->first;
  12.         } else { // radime doprostred nebo na konec fronty
  13.             item->next = queue->first;
  14.             while (item->remaining_time > temp->remaining_time && item->next->previous != NULL)
  15.                 item->next = item->next->previous;
  16.             item->previous = item->next->previous;
  17.         }
  18.     }
  19.    
  20.     if (item->next == NULL) {
  21.         queue->first = item;
  22.     } else {
  23.         queue->next->previous = item;
  24.     }
  25.    
  26.     if (item->previous == NULL) {
  27.         queue->last = item;
  28.     } else {
  29.         queue->previous->next = item;
  30.     }
  31.    
  32.     queue->size++;
  33. }
RAW Paste Data
Top