SHARE
TWEET

Untitled

a guest Nov 14th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*********************************************************************/
  2. /* Name: Insert_event                                                   */
  3. /* Description                                                          */
  4. /*    This procedure will insert the simulation event into a doubly     */
  5. /*    linked queue.  The parameters are as follows:                     */
  6. /*     etype - type of event to be inserted.                            */
  7. /*     etime - the time the event will occur.                        */
  8. /*     custind - index of the customer associated with this event.      */
  9. /* The following steps are performed:                                   */
  10. /*     1 - get a free node and add the event information.               */
  11. /*     2 - insert node into the proper place in the queue.              */
  12. /*         2a - into an empty queue.                                    */
  13. /*         2b - at the top of the queue.                                */
  14. /*         2c - at the bottom of the queue.                             */
  15. /*         2d - regular insertion (someplace in the middle).            */
  16. /*********************************************************************/
  17. void Insert_event(int etype, long int etime,struct Custs *custind)
  18.   {
  19.   int not_found;
  20.   struct event_node *loc, *pos;
  21.   loc = (struct event_node *) malloc(sizeof (struct event_node));
  22.  /* add the information to the structure */
  23.   loc->ev_type = etype;
  24.   loc->ev_time = etime;
  25.   loc->cust_index = custind;
  26.   loc->forward = NULL;
  27.   loc->backward = NULL;
  28.  /* determine if the list is empty */
  29.   if(top_event == NULL)
  30.          {
  31.          top_event = loc;
  32.          last_event = loc;
  33.          return;
  34.          }
  35.   /* see if it belongs on top */
  36.    if(top_event->ev_time > etime)
  37.          {
  38.          top_event->backward = loc;
  39.          loc->forward = top_event;
  40.          top_event = loc;
  41.          return;
  42.          }
  43.  /* see if it belongs at the bottom */
  44.   if(last_event->ev_time <= etime)
  45.          {
  46.          last_event->forward = loc;
  47.          loc->backward = last_event;
  48.          last_event = loc;
  49.          return;
  50.          }
  51.  /* it belongs somewhere in the middle so find its place */
  52.   not_found = TRUE;
  53.   pos = top_event;
  54.   while(pos != NULL && not_found)
  55.          {
  56.         if(pos->ev_time > etime)
  57.                 not_found = FALSE;
  58.          else
  59.                 pos = pos->forward;
  60.          }
  61.   /* check to see if we found something as we should have */
  62.   if(not_found)
  63.          {
  64.          printf(" ***Error - problems in insert event routine***\n");
  65.          return;
  66.          }
  67.   /* add node to appropriate place */
  68.   loc->forward = pos;
  69.   loc->backward = pos->backward;
  70.   (pos->backward)->forward = loc;
  71.   pos->backward = loc;
  72.   return;
  73. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top