// Chap 7, pp 341 - 343 // Rename this file as EL.CPP //********************************************************** // Implementation file EL.cpp for ADT event list. //********************************************************** #include "EL.h" // header file #include event::event() { } // end default constructor event::event(eventKind KindOfEvent, int EventTime, int TransactionTime): WhichEvent(KindOfEvent), Time(EventTime), TransTime(TransactionTime) { } // end constructor struct eventNode // event list node { event Event; eventPtrType Next; }; // end struct eventListClass::eventListClass() : EL(NULL) { } // end constructor eventListClass::eventListClass(const eventListClass& E) { // Implementation left as an exercise (Exercise 10). } // end copy constructor eventListClass::~eventListClass() { // Implementation left as an exercise (Exercise 10). } // end destructor boolean eventListClass::EventListIsEmpty() { return boolean(EL == NULL); } // end EventListIsEmpty void eventListClass::InsertEvent(event NewEvent, boolean& Success) { // create new node eventPtrType NewPtr = new eventNode; Success = boolean(NewPtr != NULL); if (Success) { // allocation successful; set data members of new node NewPtr->Event = NewEvent; NewPtr->Next = NULL; // if the event list is empty, simply add node if (EL == NULL) EL = NewPtr; // else if event list is not empty, insert new node // at front or end of list according to times of new // event and first event on list: // case 1 - new event is earlier or is an arrival // event at same time: insert at front of list else if ( (NewPtr->Event.Time < EL->Event.Time) || ( (NewPtr->Event.Time == EL->Event.Time) && (NewPtr->Event.WhichEvent == A) ) ) { NewPtr->Next = EL; EL = NewPtr; } // end else // case 2 - new event is later or is a departure // event at same time: insert at end of list else { NewPtr->Next = NULL; EL->Next = NewPtr; } // end if } // end if } // end InsertEvent void eventListClass::DeleteEvent(boolean& Success) { Success = boolean(!EventListIsEmpty()); if (Success) EL = EL -> Next; } // end DeleteEvent void eventListClass::RetrieveEvent(event& FirstEvent, boolean& Success) { Success = boolean(!EventListIsEmpty()); if (Success) FirstEvent = EL->Event; } // end RetrieveEvent // End of implementation file.