#include #include #include #include "process.cpp" struct processlink { process p; processlink* next; processlink* prev; }; class processList { private: processlink* first; int numProcess; public: processList(); void addProcess(); void addProcess(process, int); void addProcess(int, int); processlink* findSpot(int, processlink*); processlink* findLast(); processlink* returnFirst(); bool isEmpty(void); void printList(); void removeprocess(); processlink* getprocess(int); void delprocessblock(int); }; processList::processList(void) { first = NULL; numProcess = 0; } processlink* processList::returnFirst(void) { return first; } processlink* processList::findLast(void) { processlink* current = first; while(current->next != NULL) { current = current->next; } return current; } void processList::addProcess(void) { processlink* newlink = new processlink; processlink* current = first; newlink->p = process(); newlink->p.name = numProcess + 1; //newlink->p.display(); //cout << " xxxx " << endl; int ready = newlink->p.ready; if(current == NULL) { newlink->next = current; newlink->prev = NULL; first = newlink; } else { processlink* spot = findSpot(ready, current); if((spot->prev == NULL) && (spot->p.ready >= ready)) { newlink->next = spot; spot->prev = newlink; newlink->prev = NULL; first = newlink; } else if((spot->next == NULL) && (spot->p.ready <= ready)) { newlink->next = NULL; newlink->prev = spot; spot->next = newlink; } else { newlink->prev = spot->prev; spot->prev->next = newlink; spot->prev = newlink; newlink->next = spot; } } numProcess += 1; } processlink* processList::findSpot(int ready, processlink* current) { if((current->next == NULL) || (current->p.ready > ready)) return current; else findSpot(ready, current->next); } void processList::addProcess(process p, int quantum) { processlink* newlink = new processlink; processlink* current = first; newlink->p = p; newlink->p.work -= quantum; if(newlink->p.blocking.first != NULL) { block* current = newlink->p.blocking.first; while(current != NULL) { current->time -= quantum; current = current->nextBlock; } } //cout << " xxxx " << endl; int ready = newlink->p.ready; if(current == NULL) { newlink->next = current; newlink->prev = NULL; first = newlink; } else { processlink* spot = findSpot(ready, current); if((spot->prev == NULL) && (spot->p.ready > ready)) { newlink->next = spot; spot->prev = newlink; newlink->prev = NULL; first = newlink; } else if((spot->next == NULL) && (spot->p.ready < ready)) { newlink->next = NULL; newlink->prev = spot; spot->next = newlink; } else { newlink->prev = spot->prev; spot->prev->next = newlink; spot->prev = newlink; newlink->next = spot; } } numProcess += 1; } void processList::addProcess(int start, int name) { processlink* newlink = new processlink; processlink* current = first; newlink->p = process(start); newlink->p.name = name; newlink->p.display(); //cout << " xxxx " << endl; int ready = newlink->p.ready; if(current == NULL) { newlink->next = current; newlink->prev = NULL; first = newlink; } else { processlink* spot = findSpot(ready, current); if((spot->prev == NULL) && (spot->p.ready > ready)) { newlink->next = spot; spot->prev = newlink; newlink->prev = NULL; first = newlink; } else if((spot->next == NULL) && (spot->p.ready < ready)) { newlink->next = NULL; newlink->prev = spot; spot->next = newlink; } else { newlink->prev = spot->prev; spot->prev->next = newlink; spot->prev = newlink; newlink->next = spot; } } numProcess += 1; } bool processList::isEmpty(void) { processlink* current = first; if(current == NULL) return true; else return false; } void processList::printList(void) { processlink* current = first; while(current != NULL) { current->p.display(); current = current->next; } } void processList::removeprocess(void) { processlink* current = first; if(current->next == NULL) { first = NULL; delete current; } else { first = current->next; first->prev = NULL; first->next = current->next->next; delete current; } } processlink* processList::getprocess(int count) { processlink* current = first; while(current->p.name != count) current = current->next; return current; } void processList::delprocessblock(int dumby) { getprocess(dumby)->p.removeblock(); }