Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************/
- /* Name: Insert_event */
- /* Description */
- /* This procedure will insert the simulation event into a doubly */
- /* linked queue. The parameters are as follows: */
- /* etype - type of event to be inserted. */
- /* etime - the time the event will occur. */
- /* custind - index of the customer associated with this event. */
- /* The following steps are performed: */
- /* 1 - get a free node and add the event information. */
- /* 2 - insert node into the proper place in the queue. */
- /* 2a - into an empty queue. */
- /* 2b - at the top of the queue. */
- /* 2c - at the bottom of the queue. */
- /* 2d - regular insertion (someplace in the middle). */
- /*********************************************************************/
- void Insert_event(int etype, long int etime,struct Custs *custind)
- {
- int not_found;
- struct event_node *loc, *pos;
- loc = (struct event_node *) malloc(sizeof (struct event_node));
- /* add the information to the structure */
- loc->ev_type = etype;
- loc->ev_time = etime;
- loc->cust_index = custind;
- loc->forward = NULL;
- loc->backward = NULL;
- /* determine if the list is empty */
- if(top_event == NULL)
- {
- top_event = loc;
- last_event = loc;
- return;
- }
- /* see if it belongs on top */
- if(top_event->ev_time > etime)
- {
- top_event->backward = loc;
- loc->forward = top_event;
- top_event = loc;
- return;
- }
- /* see if it belongs at the bottom */
- if(last_event->ev_time <= etime)
- {
- last_event->forward = loc;
- loc->backward = last_event;
- last_event = loc;
- return;
- }
- /* it belongs somewhere in the middle so find its place */
- not_found = TRUE;
- pos = top_event;
- while(pos != NULL && not_found)
- {
- if(pos->ev_time > etime)
- not_found = FALSE;
- else
- pos = pos->forward;
- }
- /* check to see if we found something as we should have */
- if(not_found)
- {
- printf(" ***Error - problems in insert event routine***\n");
- return;
- }
- /* add node to appropriate place */
- loc->forward = pos;
- loc->backward = pos->backward;
- (pos->backward)->forward = loc;
- pos->backward = loc;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement